diff --git a/diboot-core/src/main/java/com/diboot/core/util/V.java b/diboot-core/src/main/java/com/diboot/core/util/V.java index 91493f4..b7a4311 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/V.java +++ b/diboot-core/src/main/java/com/diboot/core/util/V.java @@ -157,8 +157,9 @@ public class V { * @param str * @return true Or false */ - public static boolean isNumeric(String str){ - return S.isNumeric(str); + public static boolean isNumber(String str){ + String regex = "^(-?[1-9]\\d*\\.?\\d*)|(-?0\\.\\d*[1-9])|(-?[0])|(-?[0]\\.\\d*)$"; + return str.matches(regex); } /** @@ -189,22 +190,6 @@ public class V { return valid; } - /** - * 判断是否为整型数字 - * @param str - * @return - */ - public static boolean isNumber(String str) { - try{ - S.isNumeric(str); - Integer.parseInt(str); - return true; - } - catch(Exception ex){ - return false; - } - } - /** * 是否boolean值范围 */ diff --git a/diboot-core/src/main/resources/META-INF/sql/init-oracle.sql b/diboot-core/src/main/resources/META-INF/sql/init-oracle.sql index 0cb41dc..2711120 100644 --- a/diboot-core/src/main/resources/META-INF/sql/init-oracle.sql +++ b/diboot-core/src/main/resources/META-INF/sql/init-oracle.sql @@ -1,6 +1,6 @@ -- 建表 create table "dictionary" ( - "id" serial PRIMARY KEY, + "id" INTEGER generated as identity ( start with 1 nocycle noorder) not null, "parent_id" INTEGER not null, "type" VARCHAR2(50) not null, "item_name" VARCHAR2(100) not null, @@ -11,7 +11,8 @@ create table "dictionary" ( "system" SMALLINT default 0 not null, "editable" SMALLINT default 1 not null, "deleted" SMALLINT default 0 not null, - "create_time" TIMESTAMP default 'CURRENT_TIMESTAMP' not null + "create_time" TIMESTAMP default CURRENT_TIMESTAMP not null, + constraint "PK_dictionary" primary key ("id") ); -- 添加备注 comment on column "dictionary"."id" is 'ID'; @@ -31,3 +32,5 @@ comment on table "dictionary" is '数据字典'; -- 创建索引 create index "idx_directory" on "dictionary" ("type", "item_value"); + + diff --git a/diboot-core/src/main/resources/META-INF/sql/init-sqlserver.sql b/diboot-core/src/main/resources/META-INF/sql/init-sqlserver.sql index 3a87f17..9eb6523 100644 --- a/diboot-core/src/main/resources/META-INF/sql/init-sqlserver.sql +++ b/diboot-core/src/main/resources/META-INF/sql/init-sqlserver.sql @@ -15,19 +15,19 @@ create table dictionary ( constraint PK_dictionary primary key (id) ); -- 添加备注 -execute sp_addextendedproperty 'MS_Description', 'ID', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'id'; -execute sp_addextendedproperty 'MS_Description', '父ID', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'parent_id'; -execute sp_addextendedproperty 'MS_Description', '字典类型', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'type'; -execute sp_addextendedproperty 'MS_Description', '显示名', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'item_name'; -execute sp_addextendedproperty 'MS_Description', '存储值', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'item_value'; -execute sp_addextendedproperty 'MS_Description', '备注', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'comment'; -execute sp_addextendedproperty 'MS_Description', '扩展JSON', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'extdata'; -execute sp_addextendedproperty 'MS_Description', '排序号', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'sort_id'; -execute sp_addextendedproperty 'MS_Description', '是否系统预置', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'system'; -execute sp_addextendedproperty 'MS_Description', '是否可编辑', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'editable'; -execute sp_addextendedproperty 'MS_Description', '删除标记', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'deleted'; -execute sp_addextendedproperty 'MS_Description', '创建时间', 'user', '${SCHEMA}', 'table', 'dictionary', 'column', 'create_time'; +execute sp_addextendedproperty 'MS_Description', N'ID', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'id'; +execute sp_addextendedproperty 'MS_Description', N'父ID', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'parent_id'; +execute sp_addextendedproperty 'MS_Description', N'字典类型', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'type'; +execute sp_addextendedproperty 'MS_Description', N'显示名', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'item_name'; +execute sp_addextendedproperty 'MS_Description', N'存储值', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'item_value'; +execute sp_addextendedproperty 'MS_Description', N'备注', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'comment'; +execute sp_addextendedproperty 'MS_Description', N'扩展JSON', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'extdata'; +execute sp_addextendedproperty 'MS_Description', N'排序号', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'sort_id'; +execute sp_addextendedproperty 'MS_Description', N'是否系统预置', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'system'; +execute sp_addextendedproperty 'MS_Description', N'是否可编辑', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'editable'; +execute sp_addextendedproperty 'MS_Description', N'删除标记', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'deleted'; +execute sp_addextendedproperty 'MS_Description', N'创建时间', 'Schema', '${SCHEMA}', 'table', 'dictionary', 'column', 'create_time'; -execute sp_addextendedproperty 'MS_Description','数据字典','user','${SCHEMA}','table','dictionary',null,null; +execute sp_addextendedproperty 'MS_Description', N'数据字典', 'Schema', '${SCHEMA}', 'table', 'dictionary', null, null; -- 创建索引 create nonclustered index idx_directory on dictionary(type, item_value); diff --git a/diboot-docs/.vuepress/config.js b/diboot-docs/.vuepress/config.js index 22f1cc1..6921576 100644 --- a/diboot-docs/.vuepress/config.js +++ b/diboot-docs/.vuepress/config.js @@ -8,16 +8,61 @@ module.exports = { port: '9090', base: '/docs/', themeConfig: { - sidebar: 'auto', - sidebarDepth: 2, + // sidebar: 'auto', + + sidebar: { + '/guide/diboot-core/': [ + { + title: 'diboot-core指南', + collapsable: true, + sidebarDepth: 2, + children: [ + ['/guide/diboot-core/安装', '安装'], + ['/guide/diboot-core/实体Entity', '实体Entity'], + ['/guide/diboot-core/Service与实现', 'Service与实现'], + ['/guide/diboot-core/Mapper及自定义', 'Mapper及自定义'], + ['/guide/diboot-core/接口的艺术Controller', '接口的艺术Controller'], + ['/guide/diboot-core/查询条件DTO', '查询条件DTO'], + ['/guide/diboot-core/单表关联', '单表关联'], + ['/guide/diboot-core/多表关联', '多表关联'], + ['/guide/diboot-core/数据字典关联', '数据字典关联'], + ['/guide/diboot-core/异常处理', '异常处理'], + ['/guide/diboot-core/常用工具类', '常用工具类'] + ] + } + ], + '/guide/diboot-shiro/': [ + { + title: 'shiro使用指南', + collapsable: true, + sidebarDepth: 2, + children: [ + + ] + } + ], + '/guide/diboot-devtools/': [ + { + title: 'diboot-devtools指南', + collapsable: true, + sidebarDepth: 2, + children: [ + ['/guide/diboot-devtools/安装', '安装'], + ['/guide/diboot-devtools/启动', '启动'], + ['/guide/diboot-devtools/数据表管理', '数据表管理'], + ['/guide/diboot-devtools/代码生成与更新', '代码生成与更新'] + ] + } + ] + }, nav: [{ text: '首页', link: '/' }, { text: '学习', items: [ - {text: 'diboot-core指南', link: '/guide/diboot-core/'}, + {text: 'diboot-core指南', link: '/guide/diboot-core/安装'}, {text: 'diboot-shiro指南', link: '/guide/diboot-shiro/'}, - {text: 'diboot-devtools指南', link: '/guide/diboot-devtools/'} + {text: 'diboot-devtools指南', link: '/guide/diboot-devtools/安装'} ] }, { text: 'API', diff --git a/diboot-docs/guide/diboot-core/Mapper及自定义.md b/diboot-docs/guide/diboot-core/Mapper及自定义.md new file mode 100644 index 0000000..f7f3f8a --- /dev/null +++ b/diboot-docs/guide/diboot-core/Mapper及自定义.md @@ -0,0 +1 @@ +# Mapper及自定义 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/Service与实现.md b/diboot-docs/guide/diboot-core/Service与实现.md new file mode 100644 index 0000000..585aa67 --- /dev/null +++ b/diboot-docs/guide/diboot-core/Service与实现.md @@ -0,0 +1 @@ +# Service与实现 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/单表关联.md b/diboot-docs/guide/diboot-core/单表关联.md new file mode 100644 index 0000000..eeedfcb --- /dev/null +++ b/diboot-docs/guide/diboot-core/单表关联.md @@ -0,0 +1,24 @@ +# 单表关联 + +> 当两张表数据之间有直接的依赖关系时,如主外键关联关系,即可使用单表关联。在通过diboot-core的封装后, +单表关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 + +## @BindField 注解 + +该注解在单表关联时使用,用来将数据表中的某个字段映射到实体的对应字段,使用方法如下: +```java +@BindField(entity = Organization.class, field = "name", condition = "this.org_id=id") +private String orgName; +``` +使用@BindField注解时需传三个参数,分别是entity、field、condition, +entity表示关联实体,field表示关联表字段名,condition表示关联条件。 + +## @BindEntity 注解 + +该注解在单表关联时使用,用来将数据表中的某条数据映射到对应实体,使用方法如下: +```java +@BindEntity(entity = Department.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.department_id = id AND if_employee_position_department.deleted = 0") +private Department department; +``` +使用@BindEntity注解时需传两个参数,分别是entity和condition, +entity表示关联实体,condition表示关联条件。 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/多表关联.md b/diboot-docs/guide/diboot-core/多表关联.md new file mode 100644 index 0000000..ee32997 --- /dev/null +++ b/diboot-docs/guide/diboot-core/多表关联.md @@ -0,0 +1,14 @@ +# 多表关联 + +> 当两张表数据之间是通过第三张表来产生依赖关系时,即可使用多表关联。在通过diboot-core的封装后, +多表关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 + +## @BindEntityList 注解 + +该注解在多表关联时使用,用来将数据表中的单条或多条数据映射到对应的实体集合,使用方法如下: +```java +@BindEntityList(entity = Department.class, condition = "this.id = if_position_department.position_id AND if_position_department.department_id = id AND if_position_department.deleted = 0") +private List departmentList; +``` +使用@BindEntityList注解时需传两个参数,分别是entity和condition, +entity表示关联实体,condition表示关联条件。 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/安装.md b/diboot-docs/guide/diboot-core/安装.md new file mode 100644 index 0000000..f16825b --- /dev/null +++ b/diboot-docs/guide/diboot-core/安装.md @@ -0,0 +1,19 @@ +# 安装 + +## diboot-core是什么? + +> diboot-core是diboot2.0版本的核心基础框架,基于Spring,Mybatis-plus等知名开源项目。 + +* 使用diboot-core可以更加简单且方便地创建您的web后端应用,您之前的诸多工作也将得到极大的放松,我们为您准备了常用的各种工具类函数; +* 我们为你配置好了mybatis-plus,方便你进行单表CRUD无SQL的探索; +* 我们也为您提供了多表关联查询的无SQL实现方案,这里的多表不只是两张表之间的关联,而且还可以处理三张表之间的关联,只需要一个注解,你就可以快速处理完以往要好些代码才能处理好的事情; +* 我们为您提供了数据字典的管理与接口; +* 我们在diboot-core中还提供了其他常用开发场景的简单封装。 + +## 依赖引入 + +可以从**Maven中央仓库**搜索[diboot-core](https://mvnrepository.com/artifact/com.diboot/diboot-core),刷新项目即可。 + +## 初始化数据库 + +diboot-core在初次运行中,会自动安装所需数据库表,如果已经存在,则不做操作。 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/实体Entity.md b/diboot-docs/guide/diboot-core/实体Entity.md new file mode 100644 index 0000000..de5e174 --- /dev/null +++ b/diboot-docs/guide/diboot-core/实体Entity.md @@ -0,0 +1,73 @@ +# 实体Entity + +> diboot-core中的实体与1.x版本的model一样,我们为了命名更加规范,这里改用entity,下文简称实体。 + +所有实体统一存放在entity包名下,命名一般将表名转换为驼峰命名法命名再首字母大写即可,比如**sys_user**的实体名为**SysUser。** + +## BaseEntity + +> BaseEntity是diboot-core提供的基础实体类,提供了我们默认数据表结构的默认字段,比如id、deleted、create_time等,默认的方法如toMap、toString方法等。 + +## BaseExtEntity + +> BaseExtEntity是基于BaseEntity的扩展实体类,对数据表结构的扩展字段extdata添加了相关处理方法,extdata将以json字符串形式存储在数据库中。 + +* getFromExt方法 + +```java +/*** +* 从extdata JSON中提取扩展属性值 +* @param extAttrName +* @return +*/ +public Object getFromExt(String extAttrName){ + if(this.extdataMap == null){ + return null; + } + return this.extdataMap.get(extAttrName); +} + +``` + +该方法传入一个属性名称,返回该属性值 + +* addIntoExt + +```java +/*** +* 添加扩展属性和值到extdata JSON中 +* @param extAttrName +* @param extAttrValue +*/ +public void addIntoExt(String extAttrName, Object extAttrValue){ + if(extAttrName == null && extAttrValue == null){ + return; + } + if(this.extdataMap == null){ + this.extdataMap = new LinkedHashMap<>(); + } + this.extdataMap.put(extAttrName, extAttrValue); +} +``` + +该方法传入一个属性名与属性值,即可将该值设置到extdata的json字符串中。 + +## 数据校验 + +> 我们在数据提交过程中可能会需要后端进行数据格式校验,我们默认是用validation来做后端数据校验,我们可以在实体中需要校验的字段上添加校验相关的注解,如下: + +```java +@NotNull(message = "上级ID不能为空,如无请设为0") +private Long parentId; +``` + +## @TableField注解 + +> 如果mapper也继承我们core的BaseMapper来处理,那么实体中的所有字段都被认为在相对应的数据表中是存在的,如果某个字段在对应数据表中不存在,则会执行SQL时报错。 + +所以,如果某个字段在相对应的数据表中不存在,而我们又需要使用到该字段,那么可以添加@Tablefield注解,并且设置@TableField(exist = false)中的exist参数为false即可,如下: + +```java +@TableField(exist = false) +private List userIdList; +``` \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/README.md b/diboot-docs/guide/diboot-core/常用工具类.md similarity index 71% rename from diboot-docs/guide/diboot-core/README.md rename to diboot-docs/guide/diboot-core/常用工具类.md index 921a5f9..65d19bb 100644 --- a/diboot-docs/guide/diboot-core/README.md +++ b/diboot-docs/guide/diboot-core/常用工具类.md @@ -1,333 +1,6 @@ +# 常用工具类 - -# diboot-core - -## 安装 - -### diboot-core是什么? - -> diboot-core是diboot2.0版本的核心基础框架,基于Spring,Mybatis-plus等知名开源项目。 - -* 使用diboot-core可以更加简单且方便地创建您的web后端应用,您之前的诸多工作也将得到极大的放松,我们为您准备了常用的各种工具类函数; -* 我们为你配置好了mybatis-plus,方便你进行单表CRUD无SQL的探索; -* 我们也为您提供了多表关联查询的无SQL实现方案,这里的多表不只是两张表之间的关联,而且还可以处理三张表之间的关联,只需要一个注解,你就可以快速处理完以往要好些代码才能处理好的事情; -* 我们为您提供了数据字典的管理与接口; -* 我们在diboot-core中还提供了其他常用开发场景的简单封装。 - -### 依赖引入 - -可以从[maven中央仓库]([https://mvnrepository.com](https://mvnrepository.com/))搜索[diboot-core](http://),刷新项目即可。 - -### 初始化数据库 - -diboot-core在初次运行中,会自动安装所需数据库表,如果已经存在,则不做操作。 - -## 实体(Entity) - -> diboot-core中的实体与1.x版本的model一样,我们为了命名更加规范,这里改用entity,下文简称实体。 - -所有实体统一存放在entity包名下,命名一般将表名转换为驼峰命名法命名再首字母大写即可,比如**sys_user**的实体名为**SysUser。** - -### BaseEntity - -> BaseEntity是diboot-core提供的基础实体类,提供了我们默认数据表结构的默认字段,比如id、deleted、create_time等,默认的方法如toMap、toString方法等。 - -### BaseExtEntity - -> BaseExtEntity是基于BaseEntity的扩展实体类,对数据表结构的扩展字段extdata添加了相关处理方法,extdata将以json字符串形式存储在数据库中。 - -* getFromExt方法 - -```java -/*** -* 从extdata JSON中提取扩展属性值 -* @param extAttrName -* @return -*/ -public Object getFromExt(String extAttrName){ - if(this.extdataMap == null){ - return null; - } - return this.extdataMap.get(extAttrName); -} - -``` - -该方法传入一个属性名称,返回该属性值 - -* addIntoExt - -```java -/*** -* 添加扩展属性和值到extdata JSON中 -* @param extAttrName -* @param extAttrValue -*/ -public void addIntoExt(String extAttrName, Object extAttrValue){ - if(extAttrName == null && extAttrValue == null){ - return; - } - if(this.extdataMap == null){ - this.extdataMap = new LinkedHashMap<>(); - } - this.extdataMap.put(extAttrName, extAttrValue); -} -``` - -该方法传入一个属性名与属性值,即可将该值设置到extdata的json字符串中。 - -### 数据校验 - -> 我们在数据提交过程中可能会需要后端进行数据格式校验,我们默认是用validation来做后端数据校验,我们可以在实体中需要校验的字段上添加校验相关的注解,如下: - -```java -@NotNull(message = "上级ID不能为空,如无请设为0") -private Long parentId; -``` - -### @TableField注解 - -> 如果mapper也继承我们core的BaseMapper来处理,那么实体中的所有字段都被认为在相对应的数据表中是存在的,如果某个字段在对应数据表中不存在,则会执行SQL时报错。 - -所以,如果某个字段在相对应的数据表中不存在,而我们又需要使用到该字段,那么可以添加@Tablefield注解,并且设置@TableField(exist = false)中的exist参数为false即可,如下: - -```java -@TableField(exist = false) -private List userIdList; -``` - -## Service与实现 - -## Mapper及自定义 - -## 接口的艺术(Controller) - -### BaseController - -> BaseController是BaseCrudRestController的父类,提供请求参数处理等方法的封装。 - -### BaseCrudRestController - -> 增删改查通用controller,以后的controller都可以继承该类,减少代码量。 -接下来会对BaseCrudRestController中的一些通用方法进行介绍。 - -* getService 抽象方法 -```java -/** - * 获取service实例 - * - * @return - */ -protected abstract BaseService getService(); -``` -该方法是用来获取当前类中相关业务Service实例。 -所有继承了BaseCrudRestController的实体类都要实现该方法,如下: -* getService 方法实现 -```java -@Autowired -private DictionaryService dictionaryService; - -@Override -protected BaseService getService() { - return dictionaryService; -} -``` - -* getEntityList 方法 -```java -//方法定义 -protected JsonResult getEntityList(Wrapper queryWrapper) {...} -//方法调用示例 -JsonResult jsonResult = super.getEntityList(queryWrapper); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用于获取数据集合,入参为查询条件(queryWrapper), -调用该方法成功后会返回所有符合查询条件的数据集合,该方法无分页功能。 - -* getEntityListWithPaging 方法 -```java -//方法定义 -protected JsonResult getEntityListWithPaging(Wrapper queryWrapper, Pagination pagination) {...} -//方法调用示例 -JsonResult jsonResult = super.getEntityListWithPaging(queryWrapper,pagination); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用于获取数据集合,入参为查询条件(queryWrapper)、分页条件(pagination), -调用该方法成功后会返回符合查询条件的当前页数据集合,该方法有分页功能。 - -* getVOListWithPaging 方法 -```java -//方法定义 -protected JsonResult getVOListWithPaging(Wrapper queryWrapper, Pagination pagination, Class clazz) {...} -//方法调用示例 -JsonResult jsonResult = super.getVOListWithPaging(queryWrapper,pagination,Organization.class); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用来获取数据VO集合,入参为查询条件(queryWrapper)、分页条件(pagination)、类类型(clazz), -调用该方法成功后会返回符合查询条件的当前页数据VO集合,该方法有分页功能。 - -* createEntity 方法 -```java -//方法定义 -protected JsonResult createEntity(BaseEntity entity, BindingResult result) {...} -//方法调用示例 -JsonResult jsonResult = super.createEntity(entity,result); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用来新建数据,入参为数据实体(entity)、绑定结果(result),调用该方法成功后会在相关表中插入一条数据。 - -* updateEntity 方法 -```java -//方法定义 -protected JsonResult updateEntity(BaseEntity entity, BindingResult result) {...} -//方法调用示例 -JsonResult jsonResult = super.updateEntity(entity,result); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用来更新数据,入参为数据实体(entity)、绑定结果(result),调用该方法成功后会更新相关表中的数据。 - -* deleteEntity 方法 -```java - //方法定义 -protected JsonResult deleteEntity(Serializable id) {...} -//方法调用示例 -JsonResult jsonResult = super.deleteEntity(id); -System.out.println(jsonResult.getCode()==0); -//执行结果 -===> true -``` -该方法用来删除数据,入参为数据ID(id),调用该方法成功后会删除相关表中的数据。 - -* convertToVoAndBindRelations 方法 -```java -//方法定义 -protected List convertToVoAndBindRelations(List entityList, Class voClass) {...} -//方法调用示例 -List orgVOList = super.convertToVoAndBindRelations(entityList, OrganizationVO.class); -System.out.println(orgVOList.size()>0); -//执行结果 -===> true -``` -该方法用来将数据实体集合转化为数据实体VO集合,入参为实体集合(entityList)、类类型(voClass), -调用该方法成功后返回数据实体VO集合。 - -* beforeCreate 方法 -```java -//方法定义 -protected String beforeCreate(BaseEntity entity){...} -//方法调用示例 -String str = this.beforeCreate(entity); -``` -该方法用来处理新建数据之前的逻辑,如数据校验等,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 - -* afterCreated 方法 -```java - //方法定义 - protected String afterCreated(BaseEntity entity){...} - //方法调用示例 - String str = this.afterCreated(entity); -``` -该方法用来处理新建数据之后的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 - -* beforeUpdate 方法 -```java -//方法定义 -protected String beforeUpdate(BaseEntity entity){...} -//方法调用示例 -String str = this.beforeUpdate(entity); -``` -该方法用来处理更新数据之前的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 - -* afterUpdated 方法 -```java -//方法定义 -protected String afterUpdated(BaseEntity entity){...} -//方法调用示例 -String str = this.afterUpdated(entity); -``` -该方法用来处理更新数据之后的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 - -* beforeDelete 方法 -```java -//方法定义 -protected String beforeDelete(BaseEntity entity){...} -//方法调用示例 -String str = this.beforeDelete(entity); -``` -该方法主要用来处理删除数据之前的逻辑,如检验是否具有删除权限等,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 - -## 查询条件(DTO) - -## 单表关联 - -> 当两张表数据之间有直接的依赖关系时,如主外键关联关系,即可使用单表关联。在通过diboot-core的封装后, -单表关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 - -### @BindField 注解 - -该注解在单表关联时使用,用来将数据表中的某个字段映射到实体的对应字段,使用方法如下: -```java -@BindField(entity = Organization.class, field = "name", condition = "this.org_id=id") -private String orgName; -``` -使用@BindField注解时需传三个参数,分别是entity、field、condition, -entity表示关联实体,field表示关联表字段名,condition表示关联条件。 - -### @BindEntity 注解 - -该注解在单表关联时使用,用来将数据表中的某条数据映射到对应实体,使用方法如下: -```java -@BindEntity(entity = Department.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.department_id = id AND if_employee_position_department.deleted = 0") -private Department department; -``` -使用@BindEntity注解时需传两个参数,分别是entity和condition, -entity表示关联实体,condition表示关联条件。 - -## 多表关联 - -> 当两张表数据之间是通过第三张表来产生依赖关系时,即可使用多表关联。在通过diboot-core的封装后, -多表关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 - -### @BindEntityList 注解 - -该注解在多表关联时使用,用来将数据表中的单条或多条数据映射到对应的实体集合,使用方法如下: -```java -@BindEntityList(entity = Department.class, condition = "this.id = if_position_department.position_id AND if_position_department.department_id = id AND if_position_department.deleted = 0") -private List departmentList; -``` -使用@BindEntityList注解时需传两个参数,分别是entity和condition, -entity表示关联实体,condition表示关联条件。 - -## 数据字典关联 - -> 当表中的字段为数据字典类型的值时,可使用数据字典关联来绑定表字段与数据字典的关联关系。在通过diboot-core的封装后, -数据字典关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 - -### @BindDict 注解 - -该注解在数据字典关联时使用,用来将数据字典表中的某条数据映射到实体的对应字段,使用方法如下: -```java -@BindDict(type = "POSITION_LEVEL", field = "level") -private String levelLabel; -``` -使用@BindDict注解时需传两个参数,分别是type和field, -type表示关联的数据字典类型,field表示关联字段。 - -## 异常处理 - -## 常用工具类 - -### BeanUtils(Bean) +## BeanUtils(Bean) * copyProperties 方法 ```java @@ -509,7 +182,7 @@ List list = BeanUtils.extractAllFields(Organization.class); ``` 该方法用来获取类的所有属性(包含父类),入参为类类型(clazz)。 -### ContextHelper(Spring上下文) +## ContextHelper(Spring上下文) * setApplicationContext 方法 ```java @@ -575,7 +248,7 @@ List list = service.list(); ``` 该方法用来根据Entity获取对应的Service,入参为类类型(entity)。 -### D(日期时间) +## D(日期时间) * 日期、时间、星期格式常量 ```java @@ -822,7 +495,7 @@ System.out.println(date); ``` 该方法用来模糊转换日期,入参为时间字符串(dateString)。 -### Encryptor(加解密) +## Encryptor(加解密) * encrypt 方法 ```java @@ -848,7 +521,7 @@ System.out.println(decryptStr); ``` 该方法用来解密字符串,入参为需解密字符串(input)、解密秘钥(key)。 -### JSON +## JSON * stringify 方法 ```java @@ -898,7 +571,7 @@ System.out.pringtln(dictionary.getSystem()); ``` 该方法用来将JSON字符串转换为java对象,入参为JSON字符串(jsonStr)、类类型(clazz)。 -### PropertiesUtils(配置文件) +## PropertiesUtils(配置文件) * get 方法 ```java @@ -936,7 +609,7 @@ System.out.println(isOpen); ``` 该方法用来读取boolean型的配置项,入参为配置字段名(key)、配置文件名(propertiesFileName)。 -### S(字符串) +## S(字符串) * cut 方法 ```java @@ -1115,7 +788,7 @@ System.out.println(str); ``` 该方法用来将首字母转为大写,入参为字符串(input)。 -### SqlExecutor(SQL执行) +## SqlExecutor(SQL执行) * executeQuery 方法 ```java @@ -1153,7 +826,7 @@ boolean success = SqlExecutor.executeUpdate(sql, params); ``` 该方法用来执行更新操作,入参为SQL语句(sql)、更新参数(params)。 -### V(校验) +## V(校验) * isEmpty 方法 ```java diff --git a/diboot-docs/guide/diboot-core/异常处理.md b/diboot-docs/guide/diboot-core/异常处理.md new file mode 100644 index 0000000..73308d4 --- /dev/null +++ b/diboot-docs/guide/diboot-core/异常处理.md @@ -0,0 +1 @@ +# 异常处理 \ No newline at end of file diff --git a/diboot-docs/guide/diboot-core/接口的艺术Controller.md b/diboot-docs/guide/diboot-core/接口的艺术Controller.md new file mode 100644 index 0000000..b043456 --- /dev/null +++ b/diboot-docs/guide/diboot-core/接口的艺术Controller.md @@ -0,0 +1,165 @@ +# 接口的艺术Controller + +## BaseController + +> BaseController是BaseCrudRestController的父类,提供请求参数处理等方法的封装。 + +## BaseCrudRestController + +> 增删改查通用controller,以后的controller都可以继承该类,减少代码量。 +接下来会对BaseCrudRestController中的一些通用方法进行介绍。 + +* getService 抽象方法 +```java +/** + * 获取service实例 + * + * @return + */ +protected abstract BaseService getService(); +``` +该方法是用来获取当前类中相关业务Service实例。 +所有继承了BaseCrudRestController的实体类都要实现该方法,如下: +* getService 方法实现 +```java +@Autowired +private DictionaryService dictionaryService; + +@Override +protected BaseService getService() { + return dictionaryService; +} +``` + +* getEntityList 方法 +```java +//方法定义 +protected JsonResult getEntityList(Wrapper queryWrapper) {...} +//方法调用示例 +JsonResult jsonResult = super.getEntityList(queryWrapper); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用于获取数据集合,入参为查询条件(queryWrapper), +调用该方法成功后会返回所有符合查询条件的数据集合,该方法无分页功能。 + +* getEntityListWithPaging 方法 +```java +//方法定义 +protected JsonResult getEntityListWithPaging(Wrapper queryWrapper, Pagination pagination) {...} +//方法调用示例 +JsonResult jsonResult = super.getEntityListWithPaging(queryWrapper,pagination); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用于获取数据集合,入参为查询条件(queryWrapper)、分页条件(pagination), +调用该方法成功后会返回符合查询条件的当前页数据集合,该方法有分页功能。 + +* getVOListWithPaging 方法 +```java +//方法定义 +protected JsonResult getVOListWithPaging(Wrapper queryWrapper, Pagination pagination, Class clazz) {...} +//方法调用示例 +JsonResult jsonResult = super.getVOListWithPaging(queryWrapper,pagination,Organization.class); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用来获取数据VO集合,入参为查询条件(queryWrapper)、分页条件(pagination)、类类型(clazz), +调用该方法成功后会返回符合查询条件的当前页数据VO集合,该方法有分页功能。 + +* createEntity 方法 +```java +//方法定义 +protected JsonResult createEntity(BaseEntity entity, BindingResult result) {...} +//方法调用示例 +JsonResult jsonResult = super.createEntity(entity,result); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用来新建数据,入参为数据实体(entity)、绑定结果(result),调用该方法成功后会在相关表中插入一条数据。 + +* updateEntity 方法 +```java +//方法定义 +protected JsonResult updateEntity(BaseEntity entity, BindingResult result) {...} +//方法调用示例 +JsonResult jsonResult = super.updateEntity(entity,result); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用来更新数据,入参为数据实体(entity)、绑定结果(result),调用该方法成功后会更新相关表中的数据。 + +* deleteEntity 方法 +```java + //方法定义 +protected JsonResult deleteEntity(Serializable id) {...} +//方法调用示例 +JsonResult jsonResult = super.deleteEntity(id); +System.out.println(jsonResult.getCode()==0); +//执行结果 +===> true +``` +该方法用来删除数据,入参为数据ID(id),调用该方法成功后会删除相关表中的数据。 + +* convertToVoAndBindRelations 方法 +```java +//方法定义 +protected List convertToVoAndBindRelations(List entityList, Class voClass) {...} +//方法调用示例 +List orgVOList = super.convertToVoAndBindRelations(entityList, OrganizationVO.class); +System.out.println(orgVOList.size()>0); +//执行结果 +===> true +``` +该方法用来将数据实体集合转化为数据实体VO集合,入参为实体集合(entityList)、类类型(voClass), +调用该方法成功后返回数据实体VO集合。 + +* beforeCreate 方法 +```java +//方法定义 +protected String beforeCreate(BaseEntity entity){...} +//方法调用示例 +String str = this.beforeCreate(entity); +``` +该方法用来处理新建数据之前的逻辑,如数据校验等,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 + +* afterCreated 方法 +```java + //方法定义 + protected String afterCreated(BaseEntity entity){...} + //方法调用示例 + String str = this.afterCreated(entity); +``` +该方法用来处理新建数据之后的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 + +* beforeUpdate 方法 +```java +//方法定义 +protected String beforeUpdate(BaseEntity entity){...} +//方法调用示例 +String str = this.beforeUpdate(entity); +``` +该方法用来处理更新数据之前的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 + +* afterUpdated 方法 +```java +//方法定义 +protected String afterUpdated(BaseEntity entity){...} +//方法调用示例 +String str = this.afterUpdated(entity); +``` +该方法用来处理更新数据之后的逻辑,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 + +* beforeDelete 方法 +```java +//方法定义 +protected String beforeDelete(BaseEntity entity){...} +//方法调用示例 +String str = this.beforeDelete(entity); +``` +该方法主要用来处理删除数据之前的逻辑,如检验是否具有删除权限等,需要子类继承BaseCrudRestController时重写并实现具体处理逻辑。 diff --git a/diboot-docs/guide/diboot-core/数据字典关联.md b/diboot-docs/guide/diboot-core/数据字典关联.md new file mode 100644 index 0000000..91984f7 --- /dev/null +++ b/diboot-docs/guide/diboot-core/数据字典关联.md @@ -0,0 +1,14 @@ +# 数据字典关联 + +> 当表中的字段为数据字典类型的值时,可使用数据字典关联来绑定表字段与数据字典的关联关系。在通过diboot-core的封装后, +数据字典关联时开发者不再需要写大量java代码和SQL查询,只要使用相关注解即可快速绑定它们之间的关联关系。 + +## @BindDict 注解 + +该注解在数据字典关联时使用,用来将数据字典表中的某条数据映射到实体的对应字段,使用方法如下: +```java +@BindDict(type = "POSITION_LEVEL", field = "level") +private String levelLabel; +``` +使用@BindDict注解时需传两个参数,分别是type和field, +type表示关联的数据字典类型,field表示关联字段。 diff --git a/diboot-docs/guide/diboot-core/查询条件DTO.md b/diboot-docs/guide/diboot-core/查询条件DTO.md new file mode 100644 index 0000000..7810262 --- /dev/null +++ b/diboot-docs/guide/diboot-core/查询条件DTO.md @@ -0,0 +1 @@ +# 查询条件DTO \ No newline at end of file diff --git a/diboot-docs/guide/diboot-devtools/README.md b/diboot-docs/guide/diboot-devtools/README.md deleted file mode 100644 index 69db943..0000000 --- a/diboot-docs/guide/diboot-devtools/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# devtools使用文档 - -## 安装 - -### devtools是什么? - -### 安装 - -## 数据表管理 - -### 创建数据表 - -### 表数据结构 - -### 表关联 - -### 数据字典 - -### 智能补全 - -### 样例数据 - -## 代码生成与更新 - -### 基础代码生成 - -### 基础代码更新 - - - diff --git a/diboot-docs/guide/diboot-devtools/代码生成与更新.md b/diboot-docs/guide/diboot-devtools/代码生成与更新.md new file mode 100644 index 0000000..6488957 --- /dev/null +++ b/diboot-docs/guide/diboot-devtools/代码生成与更新.md @@ -0,0 +1,21 @@ +# 代码生成与更新 + +> 数据设计完成后,需要提交相关更改。点开右上角「提交更新」下拉菜单,这里有三个按钮:仅更新数据库、更新数据库和代码、重新生成代码并更新数据库。 + +## 仅更新数据库 +选择该操作,只是对**数据库表结构**及**样例数据**进行更新,不会涉及代码。 +同时,以SQL的形式保存修改内容到`update.sql`文件。 + +## 更新数据库和代码 +选择该操作,除了更新**数据库表结构**及**样例数据**以外,同时会**更新**相关代码(`Entity`、`VO`、`Service及其实现类`、`Mapper及映射文件`、`Controller`)。 +同时,以SQL的形式保存修改内容到`update.sql`文件。 +::: tip +非devtools自动生成的代码仍将保留。 +::: + +## 重新生成代码并更新数据库 +选择该操作,除了更新**数据库表结构**及**样例数据**外,同时会**重新生成**相关代码(`Entity`、`VO`、`Service及其实现类`、`Mapper及映射文件`、`Controller`)。 +同时,以SQL的形式保存修改内容到`update.sql`文件。 +::: warning +该功能是完全的重新生成代码,非devtools自动生成的代码将被覆盖!! +::: \ No newline at end of file diff --git a/diboot-docs/guide/diboot-devtools/启动.md b/diboot-docs/guide/diboot-devtools/启动.md new file mode 100644 index 0000000..502a1a9 --- /dev/null +++ b/diboot-docs/guide/diboot-devtools/启动.md @@ -0,0 +1,20 @@ +# 启动 + +## 启动项目 +以SpringBoot项目在IntelliJ IDEA中的一种启动方式为例: + +在项目入口文件 `Application` 上点击右键,在弹出的菜单上点击 `RUN 'Application'`。 +当出现类似下面提示时,表示启动成功: +``` +: Started Application in 14.223 seconds (JVM running for 16.693) +``` + +## 打开管理页面 +在控制台(Console)上的启动日志中,找到如下日志: +``` +: Diboot devtools v2.0.3 开始初始化 ... +: JDBC Connection [HikariProxyConnection@707108719 wrapping com.mysql.cj.jdbc.ConnectionImpl@7ccf6114] will not be managed by Spring +: devtools UI初始化完成,URL: http://localhost:8080/example/diboot.html +: Diboot devtools 初始化完成。 +``` +其中的`URL`即是管理页面的链接,点击打开即可。 diff --git a/diboot-docs/guide/diboot-devtools/安装.md b/diboot-docs/guide/diboot-devtools/安装.md new file mode 100644 index 0000000..90cd44f --- /dev/null +++ b/diboot-docs/guide/diboot-devtools/安装.md @@ -0,0 +1,87 @@ +# 安装 + +## diboot-devtools是什么? + +> diboot-devtools是一个面向广大程序开发人员的开发助理,有了她,你可以摆脱重复性的Coding,更专注于业务分析,提高开发效率和代码质量。 +* 安装简单,只需在项目中引入devtools依赖,添加相关配置信息后,即可启动运行。 +* 使用灵活,可按需启用更多功能。例如:是否开启引入 `Lombok`、`Swagger`等。 +* 基于主流框架,并依赖全新优化内核[diboot-core](https://github.com/dibo-software/diboot-v2/tree/master/diboot-core),保证生成的代码更简洁,质量更高。 +* 功能强大,更方便维护数据库表结构及关联关系,一键生成/更新代码。并以SQL方式保存更新内容。 +* 基于Vue开发的前端页面性能更加高效、轻量化。 + + +## 引入依赖 +* Gradle项目 +1. 添加仓库地址 +在`build.gradle`的`repositories`配置项中添加仓库地址 +``` +repositories { + maven{ url 'http://maven.diboot.com/repository/devtools/'} +} +``` +2. 引入依赖 +``` +compile ("com.diboot:diboot-devtools-spring-boot-starter:2.0.3") +``` + +* Maven项目 +1. 添加仓库地址 +在`pom.xml`的`repositories`标签中添加仓库地址 +``` + + + diboot-devtools + http://maven.diboot.com/repository/devtools/ + + +``` +2. 引入依赖 +``` + + com.diboot + diboot-devtools-spring-boot-starter + 2.0.3 + +``` + +## 添加配置信息 +* 配置信息示例 +``` +# Spring 相关配置 +spring.main.allow-bean-definition-overriding=true + +# diboot-devtools 相关配置 +diboot.devtools.codes-version=2.0.3 +diboot.devtools.codes-copyright=dibo.ltd +diboot.devtools.codes-author=diboot +diboot.devtools.output-path-entity=diboot-example/src/main/java/com/diboot/example/entity/ +diboot.devtools.output-path-vo=diboot-example/src/main/java/com/diboot/example/vo/ +diboot.devtools.output-path-service=diboot-example/src/main/java/com/diboot/example/service/ +diboot.devtools.output-path-mapper=diboot-example/src/main/java/com/diboot/example/mapper/ +diboot.devtools.output-path-controller=diboot-example/src/main/java/com/diboot/example/controller/ +diboot.devtools.output-path-sql=diboot-example/src/main/resources/ +diboot.devtools.enable-swagger=false +diboot.devtools.enable-lombok=true +diboot.devtools.enable-diboot-shiro=false +``` + +* 配置信息说明 + + * spring.main.allow-bean-definition-overriding=true:遇到同样名字的Bean时,允许覆盖。 + + **以下diboot-devtools 相关配置均可根据实际情况填写** + * diboot.devtools.codes-version:当前使用diboot-devtools的版本号。 + * diboot.devtools.codes-copyright:生成代码的版权归属,显示在每个类或接口的注释中。 + * diboot.devtools.codes-author:生成代码的作者,显示在每个类或接口的注释中。 + * diboot.devtools.output-path-*:分别指向当前项目中`Entity`、`VO`、`Service及其实现类`、`Mapper及映射文件`、`Controller`、`SQL文件所在的路径`。 + * diboot.devtools.enable-swagger:是否引入`Swagger`注解,若设置true,请注意添加Swagger依赖。 + * diboot.devtools.enable-lombok:是否引入`Lombok`注解,若设置true,请注意添加Lombok依赖。 + * diboot.devtools.enable-diboot-shiro:是否引入`diboot-shiro`注解,若设置true,请注意添加diboot-shiro依赖。 + +## 初始化数据库 +diboot-devtools在初次运行中,会自动安装所需数据库表,如果已经存在,则不做操作。 +* diboot_cloumn_ext:diboot列定义扩展表 + +::: warning +注:目前支持MySQL数据库。 +::: \ No newline at end of file diff --git a/diboot-docs/guide/diboot-devtools/数据表管理.md b/diboot-docs/guide/diboot-devtools/数据表管理.md new file mode 100644 index 0000000..6aa0f35 --- /dev/null +++ b/diboot-docs/guide/diboot-devtools/数据表管理.md @@ -0,0 +1,95 @@ +# 数据表管理 +* 项目开发过程中,通过数据库管理工具创建表时,可选择同时生成代码(`Entity`、`VO`、`Service及其实现类`、`Mapper及映射文件`、`Controller`),并保存相关SQL更新历史。 +* 通过数据库管理工具修改表、字段及关联关系时,也将同步地更改后端代码,让您彻底摆脱繁琐的CRUD。 +* 数据库管理工具中可以填写字段的样例数据,devtools会自动插入到表中作为后续生成预览等的样例展示。 + +## 创建数据表 +> 点击数据表的列表栏上方"**+**"按钮,打开创建表窗口。可以使用**引导建表**和**SQL建表**两种方式来创建数据库表。 + +1. 引导建表 + +* 数据库表名:建议使用英文小写命名,多个单词以下划线分隔。 +* 业务对象名:该数据库表所代表的业务对象中文名称,建议名词,将会用在后续的生成代码中。 +* ID策略:可选用如下ID生成方式 + * 数据库自增ID:使用数据库的自增主键,在系统中为Long类型,ID值连续,可被猜测,建议在非敏感数据的表中使用。 + * 程序生成有序ID:程序自动生成有序的非连续Long型ID,该ID为19位,且不连续,默认以该字段对列表排序,建议在要求高效率索引的敏感数据的表中使用。 (注意:后端返回前端时,该类型的ID直接转换成前端JavaScript对象时存在失真问题,如接收到json数据后前端可使用pkString代替pk/id的值,以免造成结果错误。) + * 程序生成无序ID:程序自动生成无序的32位无序字符串(UUID)来作为ID,该ID无规律可循,不可用作排序,非必需情况不建议使用。 +* 预置字段: + * id: + * extdata:扩展字段,用来存放该表各类相关冗余数据的json字符串,比如:存放冗余的创建人姓名等。 + * deleted:是否已删除,用来表明该条数据是否已删除,该字段默认为1代表已删除,0代表未删除。 + * create_by:创建人id。 + * create_time:创建时间,数据库默认值为创建时的当前系统时间。 + * update_time:更新时间,数据库默认值为更新时的当前系统时间。 + +2. SQL建表 + +在`文本框`内输入建表SQL语句,点击`确定`按钮。 + +## 数据设计 +> 在管理页面中,点击左侧**数据库表列表**中某个表,将会加载该表的所有字段到右侧面板中。 +> 点击**搜索表**输入框,输入某个表名,系统将实时搜索该表,并显示在下方的**数据库表列表**中。 + +### 表的相关配置 +1. 操作 + + 从左到右,有三个按钮: + * 按住最左侧按钮,可以上下移动改行所在的位置。 + * 中间+按钮,点击可添加一行。 + * 最右侧-按钮,点击可删除该行。 +2. 字段名 + * 字段名是数据库中的字段名称,建议使用英文小写命名,以下划线分割,如:name, teacher_id等。 + * 字段名被转化后,会自动添加到Entity类的属性中。转化过程中会将下划线去掉,并将下划线后面的首字母大写,遵循驼峰命名法。如:name, teacherId等。 + +3. 字段标签 + * 字段标签在数据库表中为该字段的comment值。 + * 代码中字段标签将显示为该字段的名称,如:姓名,教师等。 + +4. 数据类型 + * devtools提供了6种数据类型供选择,分别是:String, Long, Integer, Boolean, Date, Double。 + * Entity类中使用这里所选的数据类型。数据库表中存放的Type将会根据所选择的数据类型自动进行匹配。 + +5. 长度 + * 长度表示该字段在数据库表中设置的长度,0表示不设置长度。 + * Entity类中的属性都会使用这里的设置进行长度校验。 + +6. 扩展配置 + + 主要提供该字段的某些可供选择的特性,说明如下: + * unsigned 勾选该配置,表示这是个无符号数字,同时将该特性设置到数据库表中。 + * char 勾选该配置,在数据库表中会将该字段的type设置为char。 + * LIKE 勾选该配置,在生成映射文件(mapper.xml)时,同时也生成含有该字段LIKE的条件查询语句。 + * 对于Date类型的字段,时间格式有两种供选择:yyyy-MM-dd HH:mm:ss和yyyy-MM-dd + +7. 非空 + * 勾选了该选项的复选框,表示该字段不能为空,同时在数据库表中设置该字段非空。 + * Entity类中的属性都会使用这里的设置进行非空校验。 + +8. 默认值 + * 可以根据字段的配置,填写或选择默认值。 + * 该默认值将会设置到数据库表字段的默认值属性中。 + * 对于非空字段,尤其要注意,是否应该设置默认值。 + +9. 表单类型 + + devtools提供了常用的表单类型:`选择框`、`单行输入`、`多行输入`、`富文本编辑`、`图片上传`、`文件上传`、`忽略不显示`。 + * 表示该字段在表单页面中,以哪种方式进行数据输入,生成的代码中将包含该输入方式的相关表单元素。 + * 当一个字段选择数据类型或者关联方式后,devtools会将推荐的表单类型设置到这个字段。 + +10. 关联 + + 设置该字段关联关系的方式,可选择`无`、`数据表`、`数据字典`。 + * 选择关联`数据表`后,将会弹出可供选择的数据库表。依次是`哪个表`(关联表名)、`哪个字段`(关联表中与该字段对应的字段)、`显示的字段`(显示关联表信息的字段)。 + * 选择关联`数据字典`后,将会弹出可供选择的数据字典,选择一个元数据关联到该字段即可。 + +11. 样例数据 + + 填写样例数据,方便后续的开发调试。 + ::: warning + 注:非空字段的样例数据不能为空,并且须严格按照字段的数据类型填写。 + ::: + +### 智能补全 + +## 关系图 +> 显示数据表之间的关联关系,方便开发人员更清晰的了解项目的数据结构。