SuperAPI AI Directory

springboot-init

Coding & development

View repository

Updated 10-16 04:59

About this skill

springboot-init

Contents

  1. Tech Stack Configuration | 2. Project Structure | 3. Coding Standards | 4. Unified Response/Exceptions
  2. Permissions/Utilities/Naming | 6. Execution Workflow | 7. Prohibited Items | 8. Code Templates

0. Tech Stack Configuration

Configuration Item Recommended Choice Description
JDK 17 / 21 Spring Boot 3.x requires 17+
ORM MyBatis-Plus (MP) Default choice, rapid development. Choose Flex for ultimate performance
Utility Library Hutool / Guava Reduce reinventing the wheel, enhance development efficiency
Permissions Sa-Token / Security Choose Sa-Token for rapid development, Security for complex enterprise-level

1. Project Structure and Layering

1.1 Core Layering

  • manager: Enabled only when involving "cross-module coordination" or "third-party integration (OSS/SMS)", to avoid direct coupling.
  • common/config: Stores BaseResponse, GlobalExceptionHandler, MybatisPlusConfig , etc.

1.2 Data Flow (Strict)

  • DTO (Request): Controller for input only.
  • VO: Controller for output only.Strictly prohibitedto return Entity directly to the frontend.
  • Entity: One-to-one correspondence with database tables, only flows in the Service/Mapper layer.

2. Coding Standards

2.1 Controller & Service

  • Return Type: Mandatory use BaseResponse<T>。
  • Parameter Validation: Encapsulate multiple parameters into objects, use @RequestBody + Validation。
  • Service: Business logic converges here. MP style:extends ServiceImpl<Mapper, Entity> implements Service。

2.2 Model (Entity/DTO/VO)

  • Mandatory implementation:Serializable and declare serialVersionUID。
  • Java 17+: Prefer using record to define DTO/VO.
  • MP Annotations:@TableName, @TableId(type = IdType.ASSIGN_ID), @TableLogic。

3. Unified Response and Exceptions

  • ResultUtils: Provides success(data), error(errorCode, msg)。
  • BusinessException: Business logic errors must throw this exception, which is caught centrally by GlobalExceptionHandler .
  • ErrorCode: Maintain global status codes (e.g., 40000 parameter error, 40100 not logged in).

4. Access Control & Utility Libraries

4.1 Authentication Scheme

  • Sa-Token: Interceptor validates StpUtil.checkLogin() or @SaCheckRole。
  • Spring Security: SecurityFilterChain configuration and @PreAuthorize。

4.2 Recommended Utility Classes (Hutool)

  • StrUtil.isBlank, BeanUtil.copyProperties, JSONUtil.toJsonStr, SecureUtil.md5。

5. Naming Standards

Type Pattern Example
Controller XxxController UserController
Service XxxService/Impl UserServiceImpl
DTO XxxAdd/Update/QueryRequest UserQueryRequest
VO XxxVO UserVO
DAO XxxMapper UserMapper

6. Execution Workflow (Actionable Workflows)

6.1 Project Initialization

  1. Confirm Configuration: Identify variables such as company, project, jdk .
  2. Generate Skeleton: Create directory tree, generate pom.xml, application.yml (see templates).
  3. Inject Base Classes: Generate common, exception, utils, config package contents.

6.2 Module Addition

  1. Modeling: Create Entity -> Mapper -> Service.
  2. Business Endpoints: Define Request/VO (Record) -> Controller logic.
  3. API Documentation: Add Swagger annotations.

7. Prohibited Items

  1. Prohibited writing any business logic in the Controller.
  2. Prohibited Entity bypassing Service and being exposed directly to the Controller.
  3. Prohibited throwing raw Exception。
  4. Prohibited hardcoding roles or permission strings.

8. Code template

Reference references/code-templates.md, includes: BaseResponse, ErrorCode, BusinessException, GlobalExceptionHandler, ResultUtils, ThrowUtils, MybatisPlusConfig, JsonConfig, OpenApiConfig。