Commit ed9df112 authored by 赵啸非's avatar 赵啸非

修改数据库字段映射关键字转义问题

parent 5e3804c4
...@@ -14,6 +14,8 @@ import java.util.List; ...@@ -14,6 +14,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static com.mortals.xhx.common.key.GenConstants.KEYWORDS_SET;
/** /**
* Description:GentableColumn * Description:GentableColumn
* date: 2021-9-28 10:10:15 * date: 2021-9-28 10:10:15
...@@ -75,6 +77,14 @@ public class GentableColumnEntityExt extends BaseEntityLong { ...@@ -75,6 +77,14 @@ public class GentableColumnEntityExt extends BaseEntityLong {
return returnStr; return returnStr;
} }
public static String isKeyWord(String columnName) {
if(KEYWORDS_SET.contains(columnName)){
return "`"+columnName+'`';
}
return columnName;
}
public static String randomNumber() { public static String randomNumber() {
Faker faker = new Faker(Locale.CHINESE); Faker faker = new Faker(Locale.CHINESE);
......
...@@ -698,6 +698,10 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -698,6 +698,10 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
protected void removeAfter(Long[] ids, Context context, int result) throws AppException { protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
Long[] colIds = gentableColumnService.find(new GentableColumnQuery().tableIdList(Arrays.asList(ids))).stream().map(GentableColumnEntity::getId).toArray(Long[]::new); Long[] colIds = gentableColumnService.find(new GentableColumnQuery().tableIdList(Arrays.asList(ids))).stream().map(GentableColumnEntity::getId).toArray(Long[]::new);
gentableColumnService.remove(colIds, context); gentableColumnService.remove(colIds, context);
super.removeAfter(ids, context, result); super.removeAfter(ids, context, result);
} }
......
package com.mortals.xhx.common.key; package com.mortals.xhx.common.key;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/** /**
* 代码生成通用常量 * 代码生成通用常量
* *
...@@ -73,19 +77,19 @@ public class GenConstants { ...@@ -73,19 +77,19 @@ public class GenConstants {
/** /**
* 页面不需要编辑字段 * 页面不需要编辑字段
*/ */
public static final String[] COLUMNNAME_NOT_EDIT = {"id", "createUser","createUserId", "createTime", "delFlag","updateUser","updateUserId","updateTime", public static final String[] COLUMNNAME_NOT_EDIT = {"id", "createUser", "createUserId", "createTime", "delFlag", "updateUser", "updateUserId", "updateTime",
"updateTime"}; "updateTime"};
/** /**
* 页面不需要显示的列表字段 * 页面不需要显示的列表字段
*/ */
public static final String[] COLUMNNAME_NOT_LIST = {"id", "createUser","createUserId", "createTime", "delFlag", "updateUser","updateUserId", public static final String[] COLUMNNAME_NOT_LIST = {"id", "createUser", "createUserId", "createTime", "delFlag", "updateUser", "updateUserId",
"updateTime"}; "updateTime"};
/** /**
* 页面不需要查询字段 * 页面不需要查询字段
*/ */
public static final String[] COLUMNNAME_NOT_QUERY = {"id", "createUser","createUserId", "createTime", "delFlag", "updateUser","updateUserId", public static final String[] COLUMNNAME_NOT_QUERY = {"id", "createUser", "createUserId", "createTime", "delFlag", "updateUser", "updateUserId",
"updateTime", "remark"}; "updateTime", "remark"};
/** /**
...@@ -192,4 +196,9 @@ public class GenConstants { ...@@ -192,4 +196,9 @@ public class GenConstants {
* 不需要 * 不需要
*/ */
public static final Integer NOREQUIRE = 0; public static final Integer NOREQUIRE = 0;
public static final String[] MYSQL_KEYWORDS = {"add", "all", "alter", "analyze", "and", "as", "asc", "asensitive", "before", "between", "bigint", "binary", "blob", "both", "by", "call", "cascade", "case", "change", "char", "character", "check", "collate", "column", "condition", "connection", "constraint", "continue", "convert", "create", "cross", "current_date", "current_time", "current_timestamp", "current_user", "cursor", "database", "databases", "day_hour", "day_microsecond", "day_minute", "day_second", "dec", "decimal", "declare", "default", "delayed", "delete", "desc", "describe", "deterministic", "distinct", "distinctrow", "div", "double", "drop", "dual", "each", "else", "elseif", "enclosed", "escaped", "exists", "exit", "explain", "false", "fetch", "float", "float4", "float8", "for", "force", "foreign", "from", "fulltext", "goto", "grant", "group", "having", "high_priority", "hour_microsecond", "hour_minute", "hour_second", "if", "ignore", "in", "index", "infile", "inner", "inout", "insensitive", "insert", "int", "int1", "int2", "int3", "int4", "int8", "integer", "interval", "into", "is", "iterate", "join", "key", "keys", "kill", "label", "leading", "leave", "left", "like", "limit", "linear", "lines", "load", "localtime", "localtimestamp", "lock", "long", "longblob", "longtext", "loop", "low_priority", "match", "mediumblob", "mediumint", "mediumtext", "middleint", "minute_microsecond", "minute_second", "mod", "modifies", "natural", "not", "no_write_to_binlog", "null", "numeric", "on", "optimize", "option", "optionally", "or", "order", "out", "outer", "outfile", "precision", "primary", "procedure", "purge", "raid0", "range", "read", "reads", "real", "references", "regexp", "release", "rename", "repeat", "replace", "require", "restrict", "return", "revoke", "right", "rlike", "schema", "schemas", "second_microsecond", "select", "sensitive", "separator", "set", "show", "smallint", "spatial", "specific", "sql", "sqlexception", "sqlstate", "sqlwarning", "sql_big_result", "sql_calc_found_rows", "sql_small_result", "ssl", "starting", "straight_join", "table", "terminated", "then", "tinyblob", "tinyint", "tinytext", "to", "trailing", "trigger", "true", "undo", "union", "unique", "unlock", "unsigned", "update", "usage", "use", "using", "utc_date", "utc_time", "utc_timestamp", "values", "varbinary", "varchar", "varcharacter", "varying", "when", "where", "while", "with", "write", "x509", "xor", "year_month", "zerofill"};
public static final Set<String> KEYWORDS_SET = new HashSet<>(Arrays.asList(MYSQL_KEYWORDS));
} }
...@@ -294,7 +294,7 @@ ...@@ -294,7 +294,7 @@
<#elseif column.javaType=="String" && column.defaultValue??> <#elseif column.javaType=="String" && column.defaultValue??>
<#assign Default>"${column.defaultValue}"</#assign> <#assign Default>"${column.defaultValue}"</#assign>
<#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!=""> <#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!="">
<#assign Default>BigDecimal.valueOf(${column.defaultValue})</#assign> <#assign Default>${column.defaultValue}</#assign>
<#else> <#else>
<#assign Default>null</#assign> <#assign Default>null</#assign>
</#if> </#if>
......
...@@ -271,7 +271,7 @@ ...@@ -271,7 +271,7 @@
<#elseif column.javaType=="String" && column.defaultValue??> <#elseif column.javaType=="String" && column.defaultValue??>
<#assign Default>"${column.defaultValue}"</#assign> <#assign Default>"${column.defaultValue}"</#assign>
<#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!=""> <#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!="">
<#assign Default>BigDecimal.valueOf(${column.defaultValue})</#assign> <#assign Default>${column.defaultValue}</#assign>
<#else> <#else>
<#assign Default>null</#assign> <#assign Default>null</#assign>
</#if> </#if>
......
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
<#elseif column.javaType=="String" && column.defaultValue??> <#elseif column.javaType=="String" && column.defaultValue??>
<#assign Default>"${column.defaultValue}"</#assign> <#assign Default>"${column.defaultValue}"</#assign>
<#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!=""> <#elseif column.javaType=="BigDecimal" && column.defaultValue??&& column.defaultValue!="">
<#assign Default>BigDecimal.valueOf(${column.defaultValue})</#assign> <#assign Default>${column.defaultValue}</#assign>
<#else> <#else>
<#assign Default>null</#assign> <#assign Default>null</#assign>
</#if> </#if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment