Java Spring Boot enterprise application (v3.5.9, Java 21) with microservices architecture. Multi-module Maven project using MyBatis-Plus, Redis, RocketMQ, OAuth2, and Swagger for API documentation.
# Start required services with Docker Compose
docker-compose up -d lxq-mysql lxq-redis
# Install Maven if not available (required for build commands)
# Download from: https://maven.apache.org/download.cgi
# IDE Configuration
# Install Spring Java Format IntelliJ plugin:
# https://repo1.maven.org/maven2/io/spring/javaformat/spring-javaformat-intellij-idea-plugin
# Standard Maven commands (when Maven available)
mvn clean compile # Compile the project
mvn clean package # Package the application
mvn clean install # Install to local repository
mvn spring-boot:run # Run the application
mvn test # Run all tests
mvn spring-javaformat:apply # Format code (MANDATORY before commits)
# Environment-specific builds
mvn clean package -Pdev # Development build (default)
mvn clean package -Ptest # Test environment build
mvn clean package -Pprod # Production build
# Run single test (when tests exist)
mvn test -Dtest=ClassName#methodName
mvn test -Dtest=ClassName
# Code formatting validation (runs automatically during validate phase)
mvn validate # Check code format
com.lxq.* convention (e.g., com.lxq.admin.biz.controller)SysUserController, UserDTO)getUserById, saveUser)COMMON_STATUS, DEFAULT_PAGE_SIZE)@Data, @AllArgsConstructor, @Slf4j for boilerplate reductioncom.lxq.admin.biz.controller/ # REST endpoints (@RestController)
com.lxq.system.biz.service/ # Business logic (extends IService<Entity>)
com.lxq.system.biz.mapper/ # MyBatis data access (extends BaseMapper<Entity>)
com.lxq.system.biz.model/ # Entity classes (@TableName)
com.lxq.system.biz.domain.dto/ # Data transfer objects (@Data, @Schema)
com.lxq.system.biz.domain.vo/ # View objects for API responses
Layer Structure: Controller → Service → Mapper → Domain
@RestController, @RequestMapping, @AllArgsConstructorIService<Entity> from MyBatis-PlusBaseMapper<Entity> from MyBatis-Plus@DataRequired Annotations:
@Tag(description = "module", name = "description") // On class
@Operation(summary = "action", description = "details") // On methods
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION) // For secured APIs
Parameter Documentation: Use @ParameterObject for query parameters
Response Documentation: Use @Schema(description = "...") on DTOs/VOs
Swagger UI: Available at /doc.html when swagger.enabled=true
Example: See SysUserController.java for complete annotation patterns
Entity Conventions:
@TableName("sys_user") // Table mapping
@TableId(type = IdType.AUTO) // Auto ID generation
// Logical deletion: del_flag (0=not deleted, 1=deleted)
Mapper Patterns: Extend BaseMapper<Entity> from MyBatis-Plus
Service Patterns: Extend IService<Entity> from MyBatis-Plus
Dynamic Datasource: Use @DS("datasource_name") annotation
Query Builder: Use Wrappers.<Entity>query().lambda() for type-safe queries
Join Queries: Use MyBatis-Plus-Join for complex queries
Logical Deletion: Automatically handled (del_flag: 0/1)
Security Annotations:
@PreAuthorize("@pms.hasPermission('permission_key')") // Method security
@Inner // Internal APIs (bypass OAuth2)
@EnableLoginResourceServer / @EnableAuthResourceServer // Configuration
Security Utilities: SecurityUtils.getUser() for current user info
Permission Format: module_action (e.g., sys_user_add, sys_user_del)
Token Handling: Automatic via resource server configuration
Public Endpoints: Configure in security.oauth2.ignore.urls
spring-boot-starter-test)src/test/java following main package structure*Test.java for test classes (e.g., SysUserServiceTest)@SpringBootTest, @Test, @MockBean, @ExtendWithmvn test -Dtest=ClassName#methodName@SpringBootTest with test configuration@MockBeanResponse Wrapper: Always return R<T> from controllers
return R.ok(data); // Success response
return R.failed("error"); // Error response
return R.failed(errorEnum); // Error with enum
Logging: Use @SysLog("operation description") on service methods
Exception Handling: Use global exception handler with @RestControllerAdvice
Logging Framework: SLF4J with @Slf4j annotation
Audit Trail: @SysLog automatically logs business operations
application.yml in admin moduleapplication-{profile}.yml (dev/test/prod)@ConfigurationPropertiesspring.profiles.active=@profiles.active@swagger.* properties/v1/admin@SysLog("操作描述")
@PostMapping("/action")
@PreAuthorize("@pms.hasPermission('module_action')")
@Operation(summary = "操作", description = "详细描述")
public R<ResultVO> action(@Valid @RequestBody RequestDTO request) {
return R.ok(service.action(request));
}
@Data
@Schema(description = "对象描述")
@EqualsAndHashCode(callSuper = true)
public class EntityDTO extends Entity {
@Schema(description = "字段描述")
private String field;
}
Entity entity = service.getOne(Wrappers.<Entity>query()
.lambda()
.eq(Entity::getField, value)
.orderByDesc(Entity::getCreateTime));
mvn spring-javaformat:apply before commitsR<T> from controller methods@PreAuthorize for security checks@SysLog for business operations