support deal with column type of xxx(x,x) and some special character in ''

This commit is contained in:
moshowgame@126.com 2018-10-18 13:52:24 +08:00
parent 6fe5ffeebd
commit 4ce0ff02db
3 changed files with 22 additions and 5 deletions

View File

@ -16,6 +16,7 @@ SpringBootCodeGenerator
<tr><td>CSDN博客</td> <td>http://blog.csdn.net/moshowgame</td></tr>
<tr><td></td> <td></td></tr>
<tr><td>更新日期</td> <td>更新内容</td></tr>
<tr><td>20181018<td>支持doublt(x,x)的类型以及comment里面包含一些特殊字符的处理感谢@tanwubo的反馈)。</td></tr>
<tr><td>20181010<td>CDN变更修复CDN不稳定导致网页js报错问题。</td></tr>
<tr><td>20181003<td>新增element-ui/bootstrap生成。</td></tr>
<tr><td>20181002<td>修复公共CDN之Layer.js404问题导致项目无法生成。</td></tr>

View File

@ -102,7 +102,7 @@ public class TableParseUtil {
String fieldListTmp = tableSql.substring(tableSql.indexOf("(")+1, tableSql.lastIndexOf(")"));
// 匹配 comment替换备注里的小逗号, 防止不小心被当成切割符号切割
Matcher matcher = Pattern.compile("\\ comment `(.*?)\\`").matcher(fieldListTmp); // "\\{(.*?)\\}"
Matcher matcher = Pattern.compile("comment `(.*?)\\`").matcher(fieldListTmp); // "\\{(.*?)\\}"
while(matcher.find()){
String commentTmp = matcher.group();
@ -114,8 +114,24 @@ public class TableParseUtil {
fieldListTmp = fieldListTmp.replace(matcher.group(), commentTmpFinal);
}
}
//2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
Matcher matcher2 = Pattern.compile("\\`(.*?)\\`").matcher(fieldListTmp); // "\\{(.*?)\\}"
while(matcher2.find()){
String commentTmp2 = matcher2.group();
if (commentTmp2.contains(",")) {
String commentTmpFinal = commentTmp2.replaceAll(",", "").replaceAll("\\(", "").replaceAll("\\)", "");
fieldListTmp = fieldListTmp.replace(matcher2.group(), commentTmpFinal);
}
}
//2018-10-18 zhengkai 新增支持double(10, 2)等类型中有英文逗号的特殊情况
Matcher matcher3 = Pattern.compile("\\((.*?)\\)").matcher(fieldListTmp); // "\\{(.*?)\\}"
while(matcher3.find()){
String commentTmp3 = matcher3.group();
if (commentTmp3.contains(",")) {
String commentTmpFinal = commentTmp3.replaceAll(",", "");
fieldListTmp = fieldListTmp.replace(matcher3.group(), commentTmpFinal);
}
}
String[] fieldLineList = fieldListTmp.split(",");
if (fieldLineList.length > 0) {
int i=0;//i为了解决primary key关键字出现的地方出现在前3行一般和id有关
@ -175,7 +191,7 @@ public class TableParseUtil {
}
//解决最后一句是评论无主键且连着)的问题:album_id int(3) default '1' null comment '相册id0 代表头像 1代表照片墙')
if(commentTmp.contains(")")){
commentTmp = commentTmp.substring(0, commentTmp.lastIndexOf(")"));
commentTmp = commentTmp.substring(0, commentTmp.lastIndexOf(")")+1);
}
fieldComment = commentTmp;
}else if(tableSql.contains("comment on column")&&tableSql.contains("."+columnName+" is `")){

View File

@ -79,7 +79,7 @@ CREATE TABLE `userinfo` (
<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon">JPA</div>
<div class="input-group-text" id="btnGroupAddon">UI</div>
</div>
</div>
<div class="btn-group mr-2" role="group" aria-label="First group">