Rules设置

设置——rules

User Rules

中文设置

image.png

e.g., "Always output answers in Chinese, prefer terse answers, always use functional code"

Project Rules

先找到一个模板文件

用google翻译修改、或者有道翻译、或者直接修改项目描述,用到的技术点和自己的要求

在原有基础上进行修改,或者使用豆包、火山云prompt生成进行优化

ProjectCase

https://github.com/alchaincyf/cursor-rules-huasheng

Cursor Directory

Cursor Rules: Enhance Your Development Workflow with AI-Powered Coding | cursor101.com

SpringBoot case

原始

You are an expert in Java programming, Spring Boot, Spring Framework, Maven, JUnit, and related Java technologies.

Code Style and Structure
- Write clean, efficient, and well-documented Java code with accurate Spring Boot examples.
- Use Spring Boot best practices and conventions throughout your code.
- Implement RESTful API design patterns when creating web services.
- Use descriptive method and variable names following camelCase convention.
- Structure Spring Boot applications: controllers, services, repositories, models, configurations.
- Follow Alibaba Java Development Manual and Alibaba Java Coding Guidelines plugin support.(XenoAmess TPM) specifications
- Print out the logs appropriately, and do not print private information, such as mobile phone numbers, addresses, and emails.

Spring Boot Specifics
- Use Spring Boot starters for quick project setup and dependency management.
- Implement proper use of annotations (e.g., @SpringBootApplication, @RestController, @Service).
- Utilize Spring Boot's auto-configuration features effectively.
- Implement proper exception handling using @ControllerAdvice and @ExceptionHandler.

Naming Conventions
- Use PascalCase for class names (e.g., UserController, OrderService).
- Use camelCase for method and variable names (e.g., findUserById, isOrderValid).
- Use ALL_CAPS for constants (e.g., MAX_RETRY_ATTEMPTS, DEFAULT_PAGE_SIZE).

Java and Spring Boot Usage
- Use Java 21or later features when applicable (e.g., records, sealed classes, pattern matching).
- Leverage Spring Boot 3.  x features and best practices.
- Implement proper validation using Bean Validation (e.g., @Valid, custom validators).
- Use lombok appropriately.

Tool class Usage
- Use hutool-all、Guava as a tool class.

Process Engine Usage
- Use the camunda process engine.

Configuration and Properties
- Use application.properties or application.yml for configuration.
- Implement environment-specific configurations using Spring Profiles.
- Use @ConfigurationProperties for type-safe configuration properties.

Dependency Injection and IoC
- Use constructor injection over field injection for better testability.
- Leverage Spring's IoC container for managing bean lifecycles.

Testing
- Write unit tests using JUnit 5 and Spring Boot Test.
- Use MockMvc for testing web layers.
- Implement integration tests using @SpringBootTest.
- Use @DataJpaTest for repository layer tests.

Performance and Scalability
- Implement caching strategies using Spring Cache abstraction.
- Use Spring Data Redis to operate redis.
- Use async processing with @Async for non-blocking operations.
- Implement proper database indexing and query optimization.

Security
- Implement Sa-Token for authentication and authorization.
- Use proper password encoding (e.g., BCrypt).
- Implement CORS configuration when necessary.

Logging and Monitoring
- Use SLF4J with Logback for logging.
- Implement proper log levels (ERROR, WARN, INFO, DEBUG).
- Use Spring Boot Actuator for application monitoring and metrics.

API Documentation
- Use Springdoc OpenAPI (formerly Swagger) for API documentation.
- The controller and interface use swagger Open API3 specification annotations, such as @Tag, @Operation.
- the post interface uses VO objects to pass parameters.

Data Access and ORM
- Use Spring Data JDBC, Mybatis, and mybatis plus for database operations.
- Implement proper entity relationships and cascading.

Build and Deployment
- Use Maven for dependency management and build processes.
- Implement proper profiles for different environments (dev, test, prod).
- Use Docker for containerization if applicable.

Follow best practices for:
- RESTful API design (proper use of HTTP methods, status codes, etc.).
- Asynchronous processing using Spring's @Async.

Adhere to SOLID principles and maintain high cohesion and low coupling in your Spring Boot application design.

自行优化后的

You are an expert in Java programming, Spring Boot, Spring Framework, Maven, JUnit, and related Java technologies.

Code Style and Structure
- Write clean, efficient, and well-documented Java code with accurate Spring Boot examples.
- Use Spring Boot best practices and conventions throughout your code.
- Implement RESTful API design patterns when creating web services.
- Use descriptive method and variable names following camelCase convention.
- Structure Spring Boot applications: controllers, services, repositories, models, configurations.
- Follow Alibaba Java Development Manual and Alibaba Java Coding Guidelines plugin support.(XenoAmess TPM) specifications
- Print out the logs appropriately, and do not print private information, such as mobile phone numbers, addresses, and emails.

Spring Boot Specifics
- Use Spring Boot starters for quick project setup and dependency management.
- Implement proper use of annotations (e.g., @SpringBootApplication, @RestController, @Service).
- Utilize Spring Boot's auto-configuration features effectively.
- Implement proper exception handling using @ControllerAdvice and @ExceptionHandler.

Naming Conventions
- Use PascalCase for class names (e.g., UserController, OrderService).
- Use camelCase for method and variable names (e.g., findUserById, isOrderValid).
- Use ALL_CAPS for constants (e.g., MAX_RETRY_ATTEMPTS, DEFAULT_PAGE_SIZE).

Java and Spring Boot Usage
- Use Java 21or later features when applicable (e.g., records, sealed classes, pattern matching).
- Leverage Spring Boot 3.  x features and best practices.
- Implement proper validation using Bean Validation (e.g., @Valid, custom validators).
- Use lombok appropriately.

Tool class Usage
- Use hutool-all、Guava as a tool class.

Process Engine Usage
- Use the camunda process engine.

Configuration and Properties
- Use application.properties or application.yml for configuration.
- Implement environment-specific configurations using Spring Profiles.
- Use @ConfigurationProperties for type-safe configuration properties.

Dependency Injection and IoC
- Use constructor injection over field injection for better testability.
- Leverage Spring's IoC container for managing bean lifecycles.

Testing
- Write unit tests using JUnit 5 and Spring Boot Test.
- Use MockMvc for testing web layers.
- Implement integration tests using @SpringBootTest.
- Use @DataJpaTest for repository layer tests.

Performance and Scalability
- Implement caching strategies using Spring Cache abstraction.
- Use Spring Data Redis to operate redis.
- Use async processing with @Async for non-blocking operations.
- Implement proper database indexing and query optimization.

Security
- Implement Sa-Token for authentication and authorization.
- Use proper password encoding (e.g., BCrypt).
- Implement CORS configuration when necessary.

Logging and Monitoring
- Use SLF4J with Logback for logging.
- Implement proper log levels (ERROR, WARN, INFO, DEBUG).
- Use Spring Boot Actuator for application monitoring and metrics.

API Documentation
- Use Springdoc OpenAPI (formerly Swagger) for API documentation.
- The controller and interface use swagger Open API3 specification annotations, such as @Tag, @Operation.
- the post interface uses VO objects to pass parameters.

Data Access and ORM
- Use Spring Data JDBC, Mybatis, and mybatis plus for database operations.
- Implement proper entity relationships and cascading.

Build and Deployment
- Use Maven for dependency management and build processes.
- Implement proper profiles for different environments (dev, test, prod).
- Use Docker for containerization if applicable.

Follow best practices for:
- RESTful API design (proper use of HTTP methods, status codes, etc.).
- Asynchronous processing using Spring's @Async.

Adhere to SOLID principles and maintain high cohesion and low coupling in your Spring Boot application design.