mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 13:52:39 +08:00
Update
4.新增对复制String代码中的乱SQL代码的支持 5.优化对JSON的父子节点/处理,JSONObject和JSONArray节点处理,子节点缺失'{'头处理
This commit is contained in:
parent
dae662836b
commit
1bb8881928
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
|更新日期|更新内容|
|
|更新日期|更新内容|
|
||||||
|-|-|
|
|-|-|
|
||||||
|20191124|1.java代码结构优化. 2.新增简单的json生成模式 3.新增简单的正则表达式匹配模式(感谢@ydq的贡献) |
|
|20191124|1.java代码结构优化. 2.新增简单的json生成模式 3.新增简单的正则表达式匹配模式(感谢@ydq的贡献) 4.新增对复制String代码中的乱SQL代码的支持 5.优化对JSON的父子节点/处理,JSONObject和JSONArray节点处理,子节点缺失'{'头处理|
|
||||||
|20191123|1.移除频繁出错和被过滤的layer,改为jquery-toast. 2.Util功能优化,新增json和xml.|
|
|20191123|1.移除频繁出错和被过滤的layer,改为jquery-toast. 2.Util功能优化,新增json和xml.|
|
||||||
|20191116|优化对primary关键字的处理(感谢@liujiansgit的反馈). |
|
|20191116|优化对primary关键字的处理(感谢@liujiansgit的反馈). |
|
||||||
|20191115|1.添加tinyint类型转换(感谢@lixiliang&@liujiansgit的Suggestion) 2.添加一键复制功能(感谢@gaohanghang的Suggestion) 3.Mybatis的insert增加keyProperty="id"用于返回自增id(感谢@88888888888888888888的Suggestion) 4.优化date类型的支持(感谢@SteveLsf的反馈) 5.其他一些优化. |
|
|20191115|1.添加tinyint类型转换(感谢@lixiliang&@liujiansgit的Suggestion) 2.添加一键复制功能(感谢@gaohanghang的Suggestion) 3.Mybatis的insert增加keyProperty="id"用于返回自增id(感谢@88888888888888888888的Suggestion) 4.优化date类型的支持(感谢@SteveLsf的反馈) 5.其他一些优化. |
|
||||||
|
|||||||
@ -12,7 +12,14 @@ public class ParamInfo {
|
|||||||
private String authorName;
|
private String authorName;
|
||||||
private String packageName;
|
private String packageName;
|
||||||
private String returnUtil;
|
private String returnUtil;
|
||||||
private boolean isUnderLineToCamelCase;
|
private String nameCaseType;
|
||||||
String tinyintTransType;
|
private String tinyintTransType;
|
||||||
String dataType;
|
private String dataType;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class NAME_CASE_TYPE{
|
||||||
|
public static String CAMEL_CASE="CamelCase";
|
||||||
|
public static String UNDER_SCORE_CASE="UnderScoreCase";
|
||||||
|
public static String UPPER_UNDER_SCORE_CASE="UpperUnderScoreCase";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.softdev.system.generator.util;
|
|||||||
|
|
||||||
import cn.hutool.core.util.XmlUtil;
|
import cn.hutool.core.util.XmlUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.softdev.system.generator.entity.ClassInfo;
|
import com.softdev.system.generator.entity.ClassInfo;
|
||||||
import com.softdev.system.generator.entity.FieldInfo;
|
import com.softdev.system.generator.entity.FieldInfo;
|
||||||
@ -32,14 +33,18 @@ public class TableParseUtil {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
//process the param
|
//process the param
|
||||||
String tableSql=paramInfo.getTableSql();
|
String tableSql=paramInfo.getTableSql();
|
||||||
boolean isUnderLineToCamelCase=paramInfo.isUnderLineToCamelCase();
|
String nameCaseType=paramInfo.getNameCaseType();
|
||||||
String tinyintTransType=paramInfo.getTinyintTransType();
|
String tinyintTransType=paramInfo.getTinyintTransType();
|
||||||
|
|
||||||
if (tableSql==null || tableSql.trim().length()==0) {
|
if (tableSql==null || tableSql.trim().length()==0) {
|
||||||
throw new CodeGenerateException("Table structure can not be empty.");
|
throw new CodeGenerateException("Table structure can not be empty.");
|
||||||
}
|
}
|
||||||
|
//deal with special character
|
||||||
tableSql = tableSql.trim().replaceAll("'","`").replaceAll("\"","`").replaceAll(",",",").toLowerCase();
|
tableSql = tableSql.trim().replaceAll("'","`").replaceAll("\"","`").replaceAll(",",",").toLowerCase();
|
||||||
|
//deal with java string copy \n"
|
||||||
|
System.out.println(tableSql);
|
||||||
|
tableSql = tableSql.trim().replaceAll("n`","").replaceAll("\\+","").replaceAll("``","`").replaceAll("\\\\","");
|
||||||
|
System.out.println(tableSql);
|
||||||
// table Name
|
// table Name
|
||||||
String tableName = null;
|
String tableName = null;
|
||||||
if (tableSql.contains("TABLE") && tableSql.contains("(")) {
|
if (tableSql.contains("TABLE") && tableSql.contains("(")) {
|
||||||
@ -173,14 +178,18 @@ public class TableParseUtil {
|
|||||||
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
||||||
// field Name
|
// field Name
|
||||||
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
||||||
String fieldName;
|
String fieldName=null;
|
||||||
if(isUnderLineToCamelCase){
|
if(ParamInfo.NAME_CASE_TYPE.CAMEL_CASE.equals(nameCaseType)){
|
||||||
fieldName = StringUtils.lowerCaseFirst(StringUtils.underlineToCamelCase(columnName));
|
fieldName = StringUtils.lowerCaseFirst(StringUtils.underlineToCamelCase(columnName));
|
||||||
if (fieldName.contains("_")) {
|
if (fieldName.contains("_")) {
|
||||||
fieldName = fieldName.replaceAll("_", "");
|
fieldName = fieldName.replaceAll("_", "");
|
||||||
}
|
}
|
||||||
}else {
|
}else if(ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE.equals(nameCaseType)){
|
||||||
fieldName = StringUtils.lowerCaseFirst(columnName);
|
fieldName = StringUtils.lowerCaseFirst(columnName);
|
||||||
|
}else if(ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE.equals(nameCaseType)){
|
||||||
|
fieldName = StringUtils.lowerCaseFirst(columnName.toUpperCase());
|
||||||
|
}else{
|
||||||
|
fieldName=columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// field class
|
// field class
|
||||||
@ -305,25 +314,26 @@ public class TableParseUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ClassInfo processJsonToClassInfo(ParamInfo paramInfo){
|
public static ClassInfo processJsonToClassInfo(ParamInfo paramInfo){
|
||||||
// field List
|
|
||||||
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
|
||||||
|
|
||||||
if(JSON.isValid(paramInfo.getTableSql())){
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
|
|
||||||
jsonObject.keySet().stream().forEach(jsonField->{
|
|
||||||
FieldInfo fieldInfo = new FieldInfo();
|
|
||||||
fieldInfo.setFieldName(jsonField);
|
|
||||||
fieldInfo.setColumnName(jsonField);
|
|
||||||
fieldInfo.setFieldClass(String.class.getSimpleName());
|
|
||||||
fieldInfo.setFieldComment(jsonField);
|
|
||||||
fieldList.add(fieldInfo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
ClassInfo codeJavaInfo = new ClassInfo();
|
ClassInfo codeJavaInfo = new ClassInfo();
|
||||||
codeJavaInfo.setTableName("JsonDto");
|
codeJavaInfo.setTableName("JsonDto");
|
||||||
codeJavaInfo.setClassName("JsonDto");
|
codeJavaInfo.setClassName("JsonDto");
|
||||||
codeJavaInfo.setClassComment("JsonDto");
|
codeJavaInfo.setClassComment("JsonDto");
|
||||||
codeJavaInfo.setFieldList(fieldList);
|
|
||||||
|
//support children json if forget to add '{' in front of json
|
||||||
|
if(paramInfo.getTableSql().trim().startsWith("\"")){
|
||||||
|
paramInfo.setTableSql("{"+paramInfo.getTableSql());
|
||||||
|
}
|
||||||
|
if(JSON.isValid(paramInfo.getTableSql())){
|
||||||
|
if(paramInfo.getTableSql().trim().startsWith("{")){
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
|
||||||
|
//parse FieldList by JSONObject
|
||||||
|
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonObject));
|
||||||
|
}else if(paramInfo.getTableSql().trim().startsWith("[")){
|
||||||
|
JSONArray jsonArray=JSONArray.parseArray(paramInfo.getTableSql().trim());
|
||||||
|
//parse FieldList by JSONObject
|
||||||
|
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonArray.getJSONObject(0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return codeJavaInfo;
|
return codeJavaInfo;
|
||||||
}
|
}
|
||||||
@ -377,4 +387,39 @@ public class TableParseUtil {
|
|||||||
}
|
}
|
||||||
return codeJavaInfo;
|
return codeJavaInfo;
|
||||||
}
|
}
|
||||||
|
public static List<FieldInfo> processJsonObjectToFieldList(JSONObject jsonObject){
|
||||||
|
// field List
|
||||||
|
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||||
|
jsonObject.keySet().stream().forEach(jsonField->{
|
||||||
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
|
fieldInfo.setFieldName(jsonField);
|
||||||
|
fieldInfo.setColumnName(jsonField);
|
||||||
|
fieldInfo.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo.setFieldComment("father:"+jsonField);
|
||||||
|
fieldList.add(fieldInfo);
|
||||||
|
if(jsonObject.get(jsonField) instanceof JSONArray){
|
||||||
|
jsonObject.getJSONArray(jsonField).stream().forEach(arrayObject->{
|
||||||
|
FieldInfo fieldInfo2 = new FieldInfo();
|
||||||
|
fieldInfo2.setFieldName(arrayObject.toString());
|
||||||
|
fieldInfo2.setColumnName(arrayObject.toString());
|
||||||
|
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo2.setFieldComment("children:"+arrayObject.toString());
|
||||||
|
fieldList.add(fieldInfo2);
|
||||||
|
});
|
||||||
|
}else if(jsonObject.get(jsonField) instanceof JSONObject){
|
||||||
|
jsonObject.getJSONObject(jsonField).keySet().stream().forEach(arrayObject->{
|
||||||
|
FieldInfo fieldInfo2 = new FieldInfo();
|
||||||
|
fieldInfo2.setFieldName(arrayObject.toString());
|
||||||
|
fieldInfo2.setColumnName(arrayObject.toString());
|
||||||
|
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||||
|
fieldInfo2.setFieldComment("children:"+arrayObject.toString());
|
||||||
|
fieldList.add(fieldInfo2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(fieldList.size()<1){
|
||||||
|
throw new CodeGenerateException("JSON解析失败");
|
||||||
|
}
|
||||||
|
return fieldList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
"returnUtil":$("#returnUtil").val(),
|
"returnUtil":$("#returnUtil").val(),
|
||||||
"authorName":$("#authorName").val(),
|
"authorName":$("#authorName").val(),
|
||||||
"dataType":$("#dataType").val(),
|
"dataType":$("#dataType").val(),
|
||||||
"isUnderLineToCamelCase":$("#isUnderLineToCamelCase").val()
|
"nameCaseType":$("#nameCaseType").val()
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
@ -167,14 +167,16 @@
|
|||||||
<option value="Boolean">Boolean</option>
|
<option value="Boolean">Boolean</option>
|
||||||
<option value="Integer">Integer</option>
|
<option value="Integer">Integer</option>
|
||||||
<option value="int">int</option>
|
<option value="int">int</option>
|
||||||
|
<option value="String">String</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text">是否转换下划线为驼峰</span>
|
<span class="input-group-text">命名转换规则</span>
|
||||||
</div>
|
</div>
|
||||||
<select type="text" class="form-control" id="isUnderLineToCamelCase"
|
<select type="text" class="form-control" id="nameCaseType"
|
||||||
name="isUnderLineToCamelCase">
|
name="nameCaseType">
|
||||||
<option value="true">转换</option>
|
<option value="CamelCase">驼峰</option>
|
||||||
<option value="false">不转换</option>
|
<option value="UnderScoreCase">下划线</option>
|
||||||
|
<#--<option value="UpperUnderScoreCase">大写下划线</option>-->
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
|
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user