1
0

docs: 将 database 模块文档拆分为独立文件

This commit is contained in:
2026-04-01 17:31:25 +08:00
parent 0a7e38f931
commit 6bf9a3295a
3 changed files with 618 additions and 76 deletions

View File

@@ -31,83 +31,11 @@ com.lanyuanxiaoyao.service.template.{module}/
## database 模块
单表 CRUD → REST 接口快速实现框架。基于 JPA + Fenix + QueryDSL + MapStruct。
单表 CRUD → REST 接口快速实现框架。基于 JPA + Fenix + QueryDSL + MapStruct。
### 实体继承
```
IdOnlyEntity (id: Long, @SnowflakeId) ← @MappedSuperclass
SimpleEntity (+ createdTime: LocalDateTime, ← @MappedSuperclass
modifiedTime: LocalDateTime)
业务实体 (具体 @Entity)
```
- ID: Long雪花算法字段标 `@SnowflakeId`(自定义注解)
- 时间字段: `@CreatedDate`/`@LastModifiedDate`JPA `AuditingEntityListener` 自动填充
- 列注释: `@Column(comment = "...")`
- 物理命名: `PhysicalNamingStrategySnakeCaseImpl`camelCase→snake_case
- 保存: Fenix `saveOrUpdateByNotNullProperties()`,自动 INSERT/UPDATE仅更新非 null 字段
### Repository
```java
@NoRepositoryBean
public interface SimpleRepository<E> extends
FenixJpaRepository<E, Long>,
FenixJpaSpecificationExecutor<E>,
ListQueryByExampleExecutor<E>,
ListQuerydslPredicateExecutor<E> {}
```
业务 Repository 直接继承: `interface EmployeeRepository extends SimpleRepository<Employee> {}`
无 XML Mapper无自定义 SQL查询通过 JPA Criteria / Fenix / QueryDSL 动态构建。
### 接口组合模式
```java
SimpleService<ENTITY> extends SaveService<ENTITY>, QueryService<ENTITY>, RemoveService<ENTITY>
SimpleController<S, L, D> extends SaveController<S>, QueryController<L, D>, RemoveController
```
抽象基类: `SimpleServiceSupport`(Service) / `SimpleControllerSupport`(Controller),用 `*Support` 后缀(非 `*Impl`)。
Controller 子类必须提供三个 mapper 函数: `saveItemMapper()`, `listItemMapper()`, `detailItemMapper()`
### CRUD 五步
1. 创建实体 — 继承 `SimpleEntity`
2. 创建 Repository — 继承 `SimpleRepository<Entity>`
3. 创建 Service — 继承 `SimpleServiceSupport<Entity>`
4. 创建 DTO — 在 Controller 内定义 `SaveItem`/`ListItem`/`DetailItem` record
5. 创建 Controller — 继承 `SimpleControllerSupport<Entity, SaveItem, ListItem, DetailItem>`,实现 3 个 mapper
也可用 `DatabaseHelper.generateBasicFiles()` 自动生成上述脚手架,`@RequestMapping` 路径由实体名 camelCase→snake_case 推导。`DatabaseHelper.generateDDL()` 可从实体类生成 DDL SQL。
### API 端点
| 操作 | 方法 | 路径 |
| --------- | ---- | ---------------- |
| 新增/更新 | POST | `/save` |
| 全部列表 | GET | `/list` |
| 条件列表 | POST | `/list` |
| 详情 | GET | `/detail/{id}` |
| 删除 | GET | `/remove/{id}` |
统一响应: `GlobalResponse<T>(status:Integer, message:String, data:T)`,成功 status=0失败 status=500。
- 列表: `data = ListItem<T>(items:Iterable<T>, total:Long)`
- 详情: `data = DetailItem<T>(item:T)`
### 查询条件
查询对象: `Query(Queryable query, List<Sortable> sort, Pageable page)`
支持: equal/notEqual/like/notLike/contain/notContain/startWith/endWith/great/less/greatEqual/lessEqual/between/notBetween/inside/notInside/nullEqual/notNullEqual/empty/notEmpty
分页: `Pageable(index, size)`index 从 1 开始,默认 `(1, 10)`,无排序默认 `createdTime DESC`
**文档**
- [开发指南](docs/database-development.md) - 模块架构、核心设计、技术实现、扩展指南
- [使用指南](docs/database-usage.md) - 快速开始、API 接口、查询条件、高级用法
## 开发规范