Skip to content

Commit 83f15b4

Browse files
committed
1.一些fix,关于封装工具类以及layui模板优化等.<br> 2.优化表备注的获取逻辑.<br> 3.生成时间格式改为yyyy-MM-dd,移除具体的时间,只保留日期
1 parent a4f72c8 commit 83f15b4

File tree

24 files changed

+167
-109
lines changed

24 files changed

+167
-109
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
# Advantage
1515
- 支持DDL SQL/INSERT SQL/SIMPLE JSON生成模式
1616
- 自动记忆最近生成的内容,最多保留9个
17-
- 支持特殊字符模板(`#`请用``代替;`$`请用``代替)
1817
- 提供众多通用模板,易于使用,复制粘贴加简单修改即可完成CRUD操作
19-
18+
- 支持特殊字符模板(`#`请用``代替;`$`请用``代替)
19+
- 根据comment=(mysql)或者comment on table(pgsql/oracle)生成类名注释
2020

2121
# Url
2222

@@ -33,6 +33,7 @@
3333

3434
|更新日期|更新内容|
3535
|----|----|
36+
|20200525|1.一些fix,关于封装工具类以及layui模板优化等.<br> 2.优化表备注的获取逻辑.<br> 3.生成时间格式改为yyyy-MM-dd,移除具体的时间,只保留日期|
3637
|20200522|1.新增insert-sql模式,支持对"insert into table (xxx) values (xxx)"语句进行处理,生成java代码(感谢三叔的建议).|
3738
|20200517|1.代码重构!异常处理优化,Freemarker相关工具类优化,简化模板生成部分,通过template.json来配置需要生成的模板,不需要配置java文件.<br> 2.修复包含comment关键字时注释无法识别的问题.(感谢@1nchaos的反馈).<br> 3.赞赏优化,感谢大家的赞赏.<br> 4.新增mapper2(Mybatis-Annotation模板)(感谢@baisi525@CHKEGit的建议).|
3839
|20200503|1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理.<br> 2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈).<br> 3.修优化对所有类型的判断(感谢@cnlw的反馈).<br> 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 <br> 5.升级hutool和lombok版本|

generator-web/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class GlobalDefaultExceptionHandler {
1414
@ResponseBody
1515
public ReturnT defaultExceptionHandler(HttpServletRequest req,Exception e) {
1616
e.printStackTrace();
17-
return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
17+
return ReturnT.ERROR(e.getMessage());
1818
}
1919

2020
}

generator-web/src/main/java/com/softdev/system/generator/controller/IndexController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public String index() {
3434

3535
@PostMapping("/genCode")
3636
@ResponseBody
37-
public ReturnT<Map<String, String>> codeGenerate(@RequestBody ParamInfo paramInfo ) throws Exception {
37+
public ReturnT codeGenerate(@RequestBody ParamInfo paramInfo ) throws Exception {
3838

3939
if (paramInfo.getTableSql().trim().length()<1) {
40-
return new ReturnT<>(ReturnT.FAIL_CODE, "表结构信息不可为空");
40+
return ReturnT.ERROR("表结构信息不可为空");
4141
}
4242

4343
//1.Parse Table Structure 表结构解析
@@ -68,7 +68,7 @@ public ReturnT<Map<String, String>> codeGenerate(@RequestBody ParamInfo paramInf
6868
//3.generate the code by freemarker template and param . Freemarker根据参数和模板生成代码
6969
Map<String, String> result = generatorService.getResultByParams(params);
7070

71-
return new ReturnT<>(result);
71+
return ReturnT.SUCCESS(result);
7272
}
7373

7474
}

generator-web/src/main/java/com/softdev/system/generator/entity/ReturnT.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,61 @@
55
import java.io.Serializable;
66

77
/**
8-
* common return
9-
* @author xuxueli 2015-12-4 16:32:31
8+
* common returnT:公共返回封装类
9+
* @author zhengkai.blog.csdn.net
1010
*/
1111
@Data
12-
public class ReturnT<T> implements Serializable {
12+
public class ReturnT implements Serializable {
1313
public static final long serialVersionUID = 42L;
1414

1515
public static final int SUCCESS_CODE = 200;
1616
public static final int FAIL_CODE = 500;
17-
public static final ReturnT<String> SUCCESS = new ReturnT<>(null);
18-
public static final ReturnT<String> FAIL = new ReturnT<>(FAIL_CODE, null);
19-
17+
public static final int PAGE_CODE = 0;
18+
public static final String OBJECT_NOT_FOUND = "找不到该对象";
19+
public static final String OPERATION_SUCCESS = "操作成功";
20+
2021
private int code;
2122
private String msg;
22-
private T data;
23-
23+
private Object data;
24+
private int count;
25+
2426
public ReturnT(int code, String msg) {
2527
this.code = code;
2628
this.msg = msg;
2729
}
28-
public ReturnT(T data) {
30+
public ReturnT(int code, String msg,Object data) {
31+
this.code = code;
32+
this.msg = msg;
33+
this.data = data;
34+
}
35+
public ReturnT(Object data) {
2936
this.code = SUCCESS_CODE;
3037
this.data = data;
3138
}
32-
39+
public ReturnT( Object data , int count ) {
40+
this.code = PAGE_CODE;
41+
this.data = data;
42+
this.count = count;
43+
}
44+
public static ReturnT PAGE( Object data , int count){
45+
return new ReturnT(data,count);
46+
}
47+
public static ReturnT PAGE( Object data , long count){
48+
return new ReturnT(data,Integer.parseInt(count+""));
49+
}
50+
public static ReturnT SUCCESS(){
51+
return new ReturnT(SUCCESS_CODE,OPERATION_SUCCESS);
52+
}
53+
public static ReturnT SUCCESS(String msg){
54+
return new ReturnT(SUCCESS_CODE,msg);
55+
}
56+
public static ReturnT SUCCESS(Object data){
57+
return new ReturnT(data);
58+
}
59+
public static ReturnT ERROR(String msg){
60+
return new ReturnT(FAIL_CODE,msg);
61+
}
62+
public static ReturnT ERROR(){
63+
return new ReturnT(FAIL_CODE,OBJECT_NOT_FOUND);
64+
}
3365
}

generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,17 @@ public static ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
8080
// class Comment
8181
String classComment = null;
8282
//mysql是comment=,pgsql/oracle是comment on table,
83-
if (tableSql.contains("comment=")) {
84-
String classCommentTmp = tableSql.substring(tableSql.lastIndexOf("comment=")+8).replaceAll("`","").trim();
85-
if (classCommentTmp.indexOf(" ")!=classCommentTmp.lastIndexOf(" ")) {
86-
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf(" ")+1, classCommentTmp.lastIndexOf(" "));
87-
}
88-
if (classCommentTmp!=null && classCommentTmp.trim().length()>0) {
89-
classComment = classCommentTmp;
90-
}else{
91-
//修复表备注为空问题
92-
classComment = className;
93-
}
94-
}else if(tableSql.contains("comment on table")) {
95-
//COMMENT ON TABLE CT_BAS_FEETYPE IS 'CT_BAS_FEETYPE';
96-
String classCommentTmp = tableSql.substring(tableSql.lastIndexOf("comment on table")+17).trim();
97-
//证明这是一个常规的COMMENT ON TABLE xxx IS 'xxxx'
83+
//2020-05-25 优化表备注的获取逻辑
84+
if (tableSql.contains("comment=")||tableSql.contains("comment on table")) {
85+
String classCommentTmp = (tableSql.contains("comment="))?
86+
tableSql.substring(tableSql.lastIndexOf("comment=")+8).trim():tableSql.substring(tableSql.lastIndexOf("comment on table")+17).trim();
9887
if (classCommentTmp.contains("`")) {
9988
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`")+1);
10089
classCommentTmp = classCommentTmp.substring(0,classCommentTmp.indexOf("`"));
10190
classComment = classCommentTmp;
10291
}else{
10392
//非常规的没法分析
104-
classComment = tableName;
93+
classComment = className;
10594
}
10695
}else{
10796
//修复表备注为空问题

generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.Map;
99
/**
1010
* @description ${classInfo.classComment}
1111
* @author ${authorName}
12-
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
12+
* @date ${.now?string('yyyy-MM-dd')}
1313
*/
1414
@RestController
1515
@RequestMapping("/${classInfo.className?uncap_first}")

generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.List;
66
/**
77
* @description ${classInfo.classComment}
88
* @author ${authorName}
9-
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
9+
* @date ${.now?string('yyyy-MM-dd')}
1010
*/
1111
@Data<#if swagger?exists && swagger==true>
1212
@ApiModel("${classInfo.classComment}")</#if>

generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.util.List;
44
/**
55
* @description ${classInfo.classComment}
66
* @author ${authorName}
7-
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
7+
* @date ${.now?string('yyyy-MM-dd')}
88
*/
99
public interface I${classInfo.className}DAO {
1010

generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.util.List;
88
/**
99
* @description ${classInfo.classComment}
1010
* @author ${authorName}
11-
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
11+
* @date ${.now?string('yyyy-MM-dd')}
1212
*/
1313
@Repository
1414
public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{

generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import io.swagger.annotations.ApiModelProperty;
1515
/**
1616
* @description ${classInfo.classComment}
1717
* @author ${authorName}
18-
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
18+
* @date ${.now?string('yyyy-MM-dd')}
1919
*/
2020
@Entity
2121
@Data

0 commit comments

Comments
 (0)