在Java web开发中,虽然Spring boot已经帮助咱们简化了不少工做,但项目中庞杂的业务仍然须要本身去编写较多的 entity,vo,Mapper,Service, Controller 代码等,那么咱们有没有什么办法来简化这整个开发流程呢?java
在尝试了部分市场较为主流的自动化工具后,仍是选择了diboot-devtools这个开发者工具 ,由于她:mysql
<dependency>
<groupid>com.diboot</groupid>
<artifactid>diboot-devtools-spring-boot-starter</artifactid>
<version>2.0.3-RC2</version>
<scope>provide</scope>
</dependency>
<dependency>
<groupid>com.diboot</groupid>
<artifactid>diboot-core-spring-boot-starter</artifactid>
<version>2.0.3-RC2</version>
</dependency>
server.port=8080
server.servlet.context-path=/example
#datasource config
spring.datasource.url=jdbc:mysql://localhost:3306/demo?characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=xxxx
spring.datasource.hikari.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.hikari.maximum-pool-size=5~~~~
spring.main.allow-bean-definition-overriding=true
# devtools config
diboot.devtools.codes-author=xxx
diboot.devtools.codes-copyright=xxxx.com
diboot.devtools.codes-version=1.0.0
diboot.devtools.output-path-entity=demo/src/main/java/com/example/demo/entity/
diboot.devtools.output-path-vo=demo/src/main/java/com/example/demo/vo/
diboot.devtools.output-path-service=demo/src/main/java/com/example/demo/service/
diboot.devtools.output-path-mapper=demo/src/main/java/com/example/demo/mapper/
diboot.devtools.output-path-controller=demo/src/main/java/com/example/demo/controller/
diboot.devtools.output-path-sql=demo/src/main/resources/
diboot.devtools.enable-lombok=false
diboot.devtools.enable-swagger=false
> 在他们以前发布的diboot-core中就已经支持了关联无SQL的注解绑定方式,可见https://github.com/dibo-software/diboot-v2/tree/master/diboot-core,省去了编写关联代码,以及性能调优的相关麻烦,此次的devtools又将这些关联作到了自动化,已经再也不写关联代码就能轻松实现业务数据的多种关联关系了。git
public class DemoVO extends Demo {
private static final long serialVersionUID = -4435060215996407737L;
// status字段的关联数据字典
public static final String DICT_DEMO_STATUS = "DEMO_STATUS";
// 关联数据字典:DEMO_STATUS
@BindDict(type=DICT_DEMO_STATUS, field="status")
private String statusLabel;
public String getStatusLabel() {
return statusLabel;
}
public void setStatusLabel(String statusLabel) {
this.statusLabel = statusLabel;
}
}
public class DemoRelVO extends DemoRel {
private static final long serialVersionUID = 943963213889204702L;
// 字段关联:this.demo_id=id
@BindField(entity = Demo.class, field = "name", condition = "this.demo_id=id")
private String demoName;
public String getDemoName() {
return demoName;
}
public void setDemoName(String demoName) {
this.demoName = demoName;
}
}
多对多关联须要借助中间表来进行多对多的数据关联,但这一切devtools都帮咱们想好了,自动生成中间表。github
public class UserVO extends User {
private static final long serialVersionUID = -8863290616176144787L;
// 经过中间表的多-多Entity实体关联
@BindEntityList(entity = Role.class, condition="this.id=user_role.user_id AND user_role.role_id=id AND user_role.is_deleted=0")
private List<role> roleList;
public List<role> getRoleList() {
return roleList;
}
public void setRoleList(List<role> roleList) {
this.roleList = roleList;
}
}
以上是对diboot devtools的一些基础的使用方法及效果的介绍,还有不少方面没有介绍到,其余功能好比对swagger、对lombok等的支持,各位小伙伴能够先自我尝试下,但愿本文对各位小伙伴有所帮助,祝猿媛们多多提升效率,专一与工做中那些更加核心的部分,也少些加班,多些时间陪陪家人哦~~~ 若是您喜欢不妨 点赞、收藏、分享 三连哦,纯手打,万分感谢!web