2019-07-20 15:39:07 +08:00
|
|
|
|
# diboot-core: 全新优化内核
|
2019-06-22 16:24:18 +08:00
|
|
|
|
主要实现:
|
2019-06-22 16:01:36 +08:00
|
|
|
|
1. 多表关联的自动绑定, 实现单表CRUD和多表关联的无SQL化
|
2019-06-22 16:24:18 +08:00
|
|
|
|
2. 提供其他常用开发场景的最佳实践封装。
|
2019-06-22 16:01:36 +08:00
|
|
|
|
|
2019-07-20 15:39:07 +08:00
|
|
|
|
## ** 一. 单表CRUD无SQL
|
2019-06-22 16:24:18 +08:00
|
|
|
|
> 依赖Mybatis-Plus实现(Mybatis-Plus具备通用Mapper方案和灵活的查询构造器)
|
2019-07-20 15:39:07 +08:00
|
|
|
|
## ** 二. 多表关联查询无SQL(适用于大多数场景,拆分成单表查询自动实现结果绑定)
|
2019-06-22 16:01:36 +08:00
|
|
|
|
> 通过注解实现多数场景下的关联查询无SQL
|
2019-07-20 15:48:41 +08:00
|
|
|
|
### 1. 注解自动绑定数据字典(自定义枚举)的显示值Label
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~java
|
2019-07-20 15:48:41 +08:00
|
|
|
|
@BindDict(type="USER_STATUS", field = "status")
|
|
|
|
|
private String statusLabel;
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~
|
2019-07-20 15:39:07 +08:00
|
|
|
|
### 2. 注解自动绑定其他表的字段
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~java
|
|
|
|
|
// 支持关联条件+附加条件绑定字段
|
|
|
|
|
@BindField(entity=Department.class, field="name", condition="department_id=id AND parent_id>=0")
|
|
|
|
|
private String deptName;
|
|
|
|
|
|
|
|
|
|
// 支持通过中间表的级联关联绑定字段
|
|
|
|
|
@BindField(entity = Organization.class, field="name", condition="this.department_id=department.id AND department.org_id=id")
|
|
|
|
|
private String orgName;
|
|
|
|
|
~~~
|
2019-07-20 15:39:07 +08:00
|
|
|
|
### 3. 注解自动绑定其他表实体Entity
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~java
|
|
|
|
|
// 支持关联条件+附加条件绑定Entity
|
|
|
|
|
@BindEntity(entity = Department.class, condition="department_id=id")
|
|
|
|
|
private Department department;
|
|
|
|
|
|
|
|
|
|
// 通过中间表的级联关联绑定Entity(支持附加条件)
|
|
|
|
|
@BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id AND department.deleted=0")
|
|
|
|
|
private Organization organization;
|
|
|
|
|
~~~
|
2019-07-20 15:39:07 +08:00
|
|
|
|
### 4. 注解自动绑定其他表实体集合List<Entity>
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~java
|
|
|
|
|
// 支持关联条件+附加条件绑定多个Entity
|
|
|
|
|
@BindEntityList(entity = Department.class, condition = "id=parent_id")
|
|
|
|
|
private List<Department> children;
|
|
|
|
|
|
|
|
|
|
// 通过中间表的 多对多关联 绑定Entity(支持附加条件)
|
|
|
|
|
@BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id")
|
|
|
|
|
private List<Role> roleList;
|
2019-06-22 16:24:18 +08:00
|
|
|
|
~~~
|
|
|
|
|
|
2019-07-20 15:39:07 +08:00
|
|
|
|
## ** 三. 使用方式
|
2019-07-20 15:48:41 +08:00
|
|
|
|
### 1. 引入依赖
|
2019-07-20 15:39:07 +08:00
|
|
|
|
Gradle:
|
|
|
|
|
~~~gradle
|
|
|
|
|
compile("com.diboot:diboot-core:2.0.1")
|
|
|
|
|
~~~
|
|
|
|
|
或Maven
|
|
|
|
|
~~~xml
|
|
|
|
|
<dependency>
|
|
|
|
|
<groupId>com.diboot</groupId>
|
|
|
|
|
<artifactId>diboot-core</artifactId>
|
|
|
|
|
<version>2.0.1</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
~~~
|
2019-08-07 09:44:16 +08:00
|
|
|
|
> 注: @BindDict注解需要依赖dictionary表,初始化SQL需执行/META-INF/sql/init-mysql.sql
|
2019-07-20 15:48:41 +08:00
|
|
|
|
### 2. 定义你的Service(继承diboot的BaseService或Mybatis-plus的ISerivice)及Mapper
|
2019-07-20 15:39:07 +08:00
|
|
|
|
|
2019-07-20 15:48:41 +08:00
|
|
|
|
### 3. 使用注解绑定:
|
2019-07-20 15:39:07 +08:00
|
|
|
|
调用RelationsBinder自动绑定注解相关关联:
|
|
|
|
|
#### 方式1. 自动绑定关联(不需要转型)
|
2019-06-22 16:24:18 +08:00
|
|
|
|
~~~java
|
|
|
|
|
//List<MyUserVO> voList = ...;
|
2019-07-18 12:49:13 +08:00
|
|
|
|
RelationsBinder.bind(voList);
|
2019-06-22 16:24:18 +08:00
|
|
|
|
~~~
|
2019-07-20 15:39:07 +08:00
|
|
|
|
#### 方式2. 自动转型并绑定关联(需要转型)
|
2019-06-22 16:24:18 +08:00
|
|
|
|
~~~java
|
2019-07-20 15:39:07 +08:00
|
|
|
|
// 查询单表获取Entity集合
|
|
|
|
|
// List<User> entityList = userService.list(queryWrapper);
|
2019-07-18 12:49:13 +08:00
|
|
|
|
List<MyUserVO> voList = RelationsBinder.convertAndBind(userList, MyUserVO.class);
|
2019-06-22 16:01:36 +08:00
|
|
|
|
~~~
|
|
|
|
|
|
2019-07-20 15:48:41 +08:00
|
|
|
|
## 四. 样例参考 - [diboot-core-example](https://github.com/dibo-software/diboot-v2-example/tree/master/diboot-core-example)
|