Files
2026-05-18 09:28:15 +08:00

7.6 KiB
Raw Permalink Blame History

尚数网企业代码结构

2. 代码结构

后端(Java Spring Boot):

{backend_code_path}/
└── {company_code}-{app_code}/                    # 父模块
    ├── pom.xml
    ├── {company_code}-{app_code}-entity/        # Entity 模块
    │   └── src/main/java/{company_code}/{app_code}/
    │       ├── entity/
    │       │   └── {ModelName}Entity.java
    │       └── model/
    │           ├── {ModelName}Form.java
    │           ├── {ModelName}Pagination.java
    │           └── {ModelName}ExcelVO.java
    ├── {company_code}-{app_code}-biz/           # Biz 模块
    │   └── src/main/java/
    │       ├── {company_code}/{app_code}/
    │       │   ├── service/
    │       │   │   ├── I{ModelName}Service.java
    │       │   │   └── impl/{ModelName}ServiceImpl.java
    │       └── jnpf/mapper/       # 固定包名
    │           └── {ModelName}Mapper.java
    └── {company_code}-{app_code}-controller/   # Controller 模块
        └── src/main/java/{company_code}/{app_code}/
            └── controller/
                └── {ModelName}Controller.java

示例:当 company_code=ssw, app_code=ais 时,模块为 ssw-ais,包名为 ssw.ais.*

前端(Vue 3):

{frontend_views_path}/{app_code}/{model_name}/
├── index.vue              # 列表页
├── Form.vue               # 表单页
├── Detail.vue             # 详情页
└── helper/
    ├── api.ts             # API 调用
    ├── columnList.ts      # 列配置
    └── searchList.ts      # 搜索配置

命名规范

数据库命名

类型 规则 示例
业务表名 {business_name}(snake_case,无前缀) images
平台表名 {base_name}(base_ 前缀不变) base_user

注意:业务库已按系统名隔离,业务表用 snake_case,不加前缀,不用字符分割。 平台表(base_*)保持原样不变。

Java 类命名

类型 规则 示例
Entity {BusinessName}Entity(PascalCase) ImagesEntity
Controller {BusinessName}Controller ImagesController
Service {BusinessName}Service ImagesService
ServiceImpl {BusinessName}ServiceImpl ImagesServiceImpl
Mapper {BusinessName}Mapper ImagesMapper
Form {BusinessName}Form ImagesForm
VO {BusinessName}VO / {BusinessName}ListVO ImagesVO

注意:类名只使用业务名(PascalCase),不加 app_code 前缀,避免重复

Java 属性命名(字段)

类型 规则 示例
业务字段 {FieldName}(PascalCase) private String name;
主键 Id(PascalCase) private String id;
创建相关 CreateUser / CreateTime 等 private String createUser;

说明:Java 类属性名使用 PascalCase(与数据库 f_snake_case 字段名通过 MyBatis-Plus 自动映射)

包名规则

类型 包名规则 说明
Entity {company_code}.{app_code}.entity 数据库实体
Model {company_code}.{app_code}.model BO/VO 对象
Mapper jnpf.mapper 固定包名
Service {company_code}.{app_code}.service 业务接口
Controller {company_code}.{app_code}.controller REST 接口

变量对应关系:

变量 值 示例
company_code 企业代码 ssw
app_code 系统英文名 ais
businessName 业务名(PascalCase) Images
business_name 业务名(snake_case) images

示例:

  • company_code=ssw, app_code=ais, businessName=Images
  • 数据库表:images
  • Java 类:ImagesEntity, ImagesController, ImagesService
  • Java 属性(Entity 字段):name, fullName, createUser
  • 包名:ssw.ais.entity.ImagesEntity
  • API 路径:/api/ssw/ais/images

API 路径规则

类型 路径规则 示例
后端 Controller /api/{company_code}/{app_code}/{BusinessName} /api/ssw/ais/Images
前端 API /api/{app_code}/{enCode} /api/ais/images

说明:

  • 后端 Controller 使用完整路径 {company_code}/{app_code}/{BusinessName}
  • 前端调用后端 API 时使用 {app_code}/{enCode}(App-Code 自动追加)

POM 依赖规则

父模块 ({company_code}-{app_code}/pom.xml):

<parent>
    <groupId>com.jnpf</groupId>
    <artifactId>boot</artifactId>
    <version>6.2.0-RELEASE</version>
</parent>
<artifactId>{company_code}-{app_code}</artifactId>
<packaging>pom</packaging>
<modules>
    <module>{company_code}-{app_code}-entity</module>
    <module>{company_code}-{app_code}-biz</module>
    <module>{company_code}-{app_code}-controller</module>
</modules>

Entity 模块 ({company_code}-{app_code}-entity/pom.xml):

<parent>
    <artifactId>{company_code}-{app_code}</artifactId>
    <groupId>com.jnpf</groupId>
    <version>6.2.0-RELEASE</version>
</parent>
<artifactId>{company_code}-{app_code}-entity</artifactId>
<!-- 依赖 -->
<dependencies>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>jnpf-common-all</artifactId>
    </dependency>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>jnpf-generater-base</artifactId>
    </dependency>
</dependencies>

Biz 模块 ({company_code}-{app_code}-biz/pom.xml):

<parent>
    <artifactId>{company_code}-{app_code}</artifactId>
    <groupId>com.jnpf</groupId>
    <version>6.2.0-RELEASE</version>
</parent>
<artifactId>{company_code}-{app_code}-biz</artifactId>
<!-- 依赖 -->
<dependencies>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>{company_code}-{app_code}-entity</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.12.0</version>
    </dependency>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>jnpf-common-all</artifactId>
    </dependency>
</dependencies>

Controller 模块 ({company_code}-{app_code}-controller/pom.xml):

<parent>
    <artifactId>{company_code}-{app_code}</artifactId>
    <groupId>com.jnpf</groupId>
    <version>6.2.0-RELEASE</version>
</parent>
<artifactId>{company_code}-{app_code}-controller</artifactId>
<!-- 依赖 -->
<dependencies>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>{company_code}-{app_code}-biz</artifactId>
    </dependency>
    <dependency>
        <groupId>com.jnpf</groupId>
        <artifactId>jnpf-common-all</artifactId>
    </dependency>
</dependencies>

依赖层级图

Controller ({company_code}-{app_code}-controller)
    └── Biz ({company_code}-{app_code}-biz)
          ├── Entity ({company_code}-{app_code}-entity)
          │     ├── jnpf-common-all
          │     └── jnpf-generater-base
          ├── fastjson
          ├── commons-lang3 (3.12.0)
          └── jnpf-common-all
    └── jnpf-common-all

关键依赖说明

Artifact ID 说明
jnpf-common-all JNPF 公共模块,所有层级都需要
jnpf-generater-base 代码生成基础模块,仅 Entity 层需要
fastjson JSON 处理,仅 Biz 层需要
commons-lang3 工具类库,仅 Biz 层需要