在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又將這些關聯作到了自動化,已經再也不寫關聯代碼就能輕鬆實現業務數據的多種關聯關係了。
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都幫咱們想好了,自動生成中間表。
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; } }
*~~~~ 重啓應用後,訪問user的列表接口,便可看到關聯數據的結果了:git
以上是對diboot devtools的一些基礎的使用方法及效果的介紹,還有不少方面沒有介紹到,其餘功能好比對swagger、對lombok等的支持,各位小夥伴能夠先自我嘗試下,但願本文對各位小夥伴有所幫助,祝猿媛們多多提升效率,專一與工做中那些更加核心的部分,也少些加班,多些時間陪陪家人哦~~~ 若是您喜歡不妨 點贊、收藏、分享 三連哦,純手打,萬分感謝!