Commit 75e74d54 authored by yanzg's avatar yanzg

常规BUG的修改

parent 1dd16657
...@@ -74,39 +74,39 @@ public class DaoConst { ...@@ -74,39 +74,39 @@ public class DaoConst {
* 单位地址 * 单位地址
*/ */
public static final int CODE_UNIT = 2; public static final int CODE_UNIT = 2;
/** /**
* 表名代码片段 * 插入SQL语句模板
*/ */
public static final String TABLE_CODE = "{TABLE}"; public static final String SQL_INSERT = "INSERT INTO {TABLE}({FIELD}) VALUES({VALUES})";
/** /**
* 字段代码片段 * 更新SQL语句模板
*/ */
public static final String FIELD_CODE = "{FIELD}"; public static final String SQL_UPDATE = "UPDATE {TABLE} AS a {INNER} SET {FIELD} WHERE 1=1 {WHERE}";
/** /**
* 值代码片段 * 删除SQL语句模板
*/ */
public static final String VALUES_CODE = "{VALUES}"; public static final String SQL_REMOVE = "DELETE a FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
/** /**
* WHERE条件代码片段 * 加载SQL语句模板
*/ */
public static final String WHERE_CODE = "{WHERE}"; public static final String SQL_LOAD = "SELECT a.*{FIELD} FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}";
/** /**
* 插入SQL语句模板 * 表名代码片段
*/ */
public static final String INSERT_MODEL = "INSERT INTO {TABLE}({FIELD}) VALUES({VALUES})"; public static final String CODE_TABLE = "{TABLE}";
/** /**
* 更新SQL语句模板 * 字段代码片段
*/ */
public static final String UPDATE_MODEL = "UPDATE {TABLE} AS a {INNER} SET {FIELD} WHERE 1=1 {WHERE}"; public static final String CODE_FIELD = "{FIELD}";
/** /**
* 删除SQL语句模板 * 值代码片段
*/ */
public static final String REMOVE_MODEL = "DELETE a FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}"; public static final String CODE_VALUES = "{VALUES}";
/** /**
* 加载SQL语句模板 * WHERE条件代码片段
*/ */
public static final String LOAD_MODEL = "SELECT a.*{FIELD} FROM {TABLE} AS a {INNER} WHERE 1=1 {WHERE}"; public static final String CODE_WHERE = "{WHERE}";
/** /**
* 更新字段模板 * 更新字段模板
*/ */
......
package com.yanzuoguang.dao; package com.yanzuoguang.dao;
import com.yanzuoguang.util.helper.StringHelper;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
...@@ -18,7 +20,7 @@ public @interface TableAnnotation { ...@@ -18,7 +20,7 @@ public @interface TableAnnotation {
* *
* @return * @return
*/ */
String value(); String value() default StringHelper.EMPTY;
/** /**
* 字段类型 * 字段类型
......
...@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl; ...@@ -2,7 +2,6 @@ package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.DaoConst; import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.TableAnnotation; import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.base.MethodField; import com.yanzuoguang.util.base.MethodField;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
...@@ -85,7 +84,9 @@ public class TableStruct { ...@@ -85,7 +84,9 @@ public class TableStruct {
// 注解不为空,则修改后台数据库映射字段、字段类型 // 注解不为空,则修改后台数据库映射字段、字段类型
if (annotation != null) { if (annotation != null) {
fieldName = annotation.value(); if (!StringHelper.isEmpty(annotation.value())) {
fieldName = annotation.value();
}
fieldAction = annotation.type(); fieldAction = annotation.type();
} }
...@@ -110,7 +111,9 @@ public class TableStruct { ...@@ -110,7 +111,9 @@ public class TableStruct {
// 将所有非主键列添加到普通列 // 将所有非主键列添加到普通列
commonActionList.add(vo); commonActionList.add(vo);
boolean isTypeMany = resultActionType == DaoConst.FIELD_REMOVE_UPDATE || resultActionType == DaoConst.FIELD_CREATE; boolean isTypeMany = resultActionType != DaoConst.FIELD_MD5
&& resultActionType != DaoConst.FIELD_REMOVE
&& resultActionType != DaoConst.FIELD_VERSION;
if (isTypeMany) { if (isTypeMany) {
List<TableFieldVo> actionList = this.getFieldActionList(resultActionType); List<TableFieldVo> actionList = this.getFieldActionList(resultActionType);
actionList.add(vo); actionList.add(vo);
...@@ -389,20 +392,20 @@ public class TableStruct { ...@@ -389,20 +392,20 @@ public class TableStruct {
*/ */
private SqlData releaseSqlCreate() { private SqlData releaseSqlCreate() {
// 生成添加的SQL语句 // 生成添加的SQL语句
String text = DaoConst.INSERT_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_INSERT.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.CREATE, text); SqlData sql = new SqlData(DaoConst.CREATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_CREATE); sql.setSqlType(DaoConst.SQL_TYPE_CREATE);
// 第一个增加的字段,不需要增加 "," // 第一个增加的字段,不需要增加 ","
String flag = StringHelper.EMPTY; String flag = StringHelper.EMPTY;
if (this.getKeyType() == String.class) { if (this.getKeyType() == String.class) {
sql.addParaConst(this.getKey().inputName, DaoConst.FIELD_CODE, this.getKey().name, sql.addParaConst(this.getKey().inputName, DaoConst.CODE_FIELD, this.getKey().name,
DaoConst.VALUES_CODE, DaoConst.CODE_PARA DaoConst.CODE_VALUES, DaoConst.CODE_PARA
); );
flag = DaoConst.CODE_SPLIT; flag = DaoConst.CODE_SPLIT;
} }
for (TableFieldVo field : this.getFields()) { for (TableFieldVo field : this.getFields()) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, flag + field.name, sql.addParaConst(field.inputName, DaoConst.CODE_FIELD, flag + field.name,
DaoConst.VALUES_CODE, flag + DaoConst.CODE_PARA DaoConst.CODE_VALUES, flag + DaoConst.CODE_PARA
); );
flag = DaoConst.CODE_SPLIT; flag = DaoConst.CODE_SPLIT;
} }
...@@ -416,12 +419,12 @@ public class TableStruct { ...@@ -416,12 +419,12 @@ public class TableStruct {
*/ */
private SqlData releaseSqlUpdate() { private SqlData releaseSqlUpdate() {
// 生成添加的SQL语句 // 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_UPDATE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.UPDATE, text); SqlData sql = new SqlData(DaoConst.UPDATE, text);
sql.setSqlType(DaoConst.SQL_TYPE_UPDATE); sql.setSqlType(DaoConst.SQL_TYPE_UPDATE);
// 主键字段操作 // 主键字段操作
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_PRIMARY, this.getKey().name, this.getKey().name)); sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_PRIMARY, this.getKey().name, this.getKey().name));
sql.addConst(this.getKey().inputName, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, this.getKey().name)); sql.addConst(this.getKey().inputName, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, this.getKey().name));
// 增加普通代码片段字段 // 增加普通代码片段字段
...@@ -429,7 +432,7 @@ public class TableStruct { ...@@ -429,7 +432,7 @@ public class TableStruct {
DaoConst.FIELD_CREATE, DaoConst.FIELD_REMOVE, DaoConst.FIELD_VERSION); DaoConst.FIELD_CREATE, DaoConst.FIELD_REMOVE, DaoConst.FIELD_VERSION);
for (TableFieldVo field : updateList) { for (TableFieldVo field : updateList) {
sql.addParaConst(field.inputName, sql.addParaConst(field.inputName,
DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name) DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
); );
} }
// 添加删除字段 // 添加删除字段
...@@ -450,17 +453,17 @@ public class TableStruct { ...@@ -450,17 +453,17 @@ public class TableStruct {
private SqlData releaseSqlRemove() { private SqlData releaseSqlRemove() {
if (this.getRemove() != null) { if (this.getRemove() != null) {
// 生成添加的SQL语句 // 生成添加的SQL语句
String text = DaoConst.UPDATE_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_UPDATE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.REMOVE, text); SqlData sql = new SqlData(DaoConst.REMOVE, text);
sql.setSqlType(DaoConst.SQL_TYPE_REMOVE); sql.setSqlType(DaoConst.SQL_TYPE_REMOVE);
// 设置删除字段标记 // 设置删除字段标记
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_REMOVE, this.getRemove().name)); sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_REMOVE, this.getRemove().name));
// 设置删除时需要修改的字段的值 // 设置删除时需要修改的字段的值
for (TableFieldVo field : this.getFieldActionList(DaoConst.FIELD_REMOVE_UPDATE)) { for (TableFieldVo field : this.getFieldActionList(DaoConst.FIELD_REMOVE_UPDATE)) {
sql.addParaConst(field.inputName, sql.addParaConst(field.inputName,
DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name) DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_FIELD_PARA, field.name)
); );
} }
// 增加版本号字段的值 // 增加版本号字段的值
...@@ -469,7 +472,7 @@ public class TableStruct { ...@@ -469,7 +472,7 @@ public class TableStruct {
addWhereField(sql, DaoConst.CODE_TAG, true); addWhereField(sql, DaoConst.CODE_TAG, true);
return sql; return sql;
} else { } else {
String text = DaoConst.REMOVE_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_REMOVE.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.REMOVE, text); SqlData sql = new SqlData(DaoConst.REMOVE, text);
// 生成删除语句Where条件 // 生成删除语句Where条件
addWhereField(sql, DaoConst.CODE_TAG, true); addWhereField(sql, DaoConst.CODE_TAG, true);
...@@ -484,7 +487,7 @@ public class TableStruct { ...@@ -484,7 +487,7 @@ public class TableStruct {
*/ */
private SqlData releaseSqlLoad() { private SqlData releaseSqlLoad() {
// 生成添加的SQL语句 // 生成添加的SQL语句
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_LOAD.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(DaoConst.LOAD, text); SqlData sql = new SqlData(DaoConst.LOAD, text);
sql.setSqlType(DaoConst.SQL_TYPE_LOAD); sql.setSqlType(DaoConst.SQL_TYPE_LOAD);
// 生成加载语句的WHERE条件 // 生成加载语句的WHERE条件
...@@ -529,7 +532,7 @@ public class TableStruct { ...@@ -529,7 +532,7 @@ public class TableStruct {
private void addWhereRemove(SqlData sql) { private void addWhereRemove(SqlData sql) {
if (getRemove() != null) { if (getRemove() != null) {
sql.addParaConst(DaoConst.REMOVE_FLAG_INPUT, sql.addParaConst(DaoConst.REMOVE_FLAG_INPUT,
DaoConst.WHERE_CODE, DaoConst.CODE_WHERE,
String.format(DaoConst.CODE_WHERE_EQUALS_NOT_REMOVE, this.getRemove().name) String.format(DaoConst.CODE_WHERE_EQUALS_NOT_REMOVE, this.getRemove().name)
); );
} }
...@@ -543,7 +546,7 @@ public class TableStruct { ...@@ -543,7 +546,7 @@ public class TableStruct {
private void addUpdateVersion(SqlData sql) { private void addUpdateVersion(SqlData sql) {
// 添加版本字段 // 添加版本字段
if (getVersion() != null) { if (getVersion() != null) {
sql.addCode(DaoConst.FIELD_CODE, String.format(DaoConst.CODE_UPDATE_VERSION_FIELD, getVersion().name, getVersion().name)); sql.addCode(DaoConst.CODE_FIELD, String.format(DaoConst.CODE_UPDATE_VERSION_FIELD, getVersion().name, getVersion().name));
} }
} }
...@@ -562,17 +565,17 @@ public class TableStruct { ...@@ -562,17 +565,17 @@ public class TableStruct {
// 参数字段 // 参数字段
List<String> paraFields = new ArrayList<String>(); List<String> paraFields = new ArrayList<String>();
// 生成修改的SQL语句 // 生成修改的SQL语句
SqlData sql = new SqlData(name, model.replace(DaoConst.TABLE_CODE, this.name)); SqlData sql = new SqlData(name, model.replace(DaoConst.CODE_TABLE, this.name));
sql.setSqlType(sqlType); sql.setSqlType(sqlType);
// 生成添加的SQL语句 // 生成添加的SQL语句
String flag = StringHelper.EMPTY; String flag = StringHelper.EMPTY;
for (TableFieldVo field : valueFields) { for (TableFieldVo field : valueFields) {
sql.addParaConst(field.inputName, DaoConst.FIELD_CODE, flag + valueModel.replace(DaoConst.FIELD_CODE, field.name)); sql.addParaConst(field.inputName, DaoConst.CODE_FIELD, flag + valueModel.replace(DaoConst.CODE_FIELD, field.name));
flag = DaoConst.CODE_SPLIT; flag = DaoConst.CODE_SPLIT;
} }
for (TableFieldVo field : whereFields) { for (TableFieldVo field : whereFields) {
sql.addParaConst(field.inputName, DaoConst.WHERE_CODE, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, field.name)); sql.addParaConst(field.inputName, DaoConst.CODE_WHERE, String.format(DaoConst.CODE_WHERE_EQUALS_PARA, field.name));
} }
return sql; return sql;
...@@ -611,7 +614,7 @@ public class TableStruct { ...@@ -611,7 +614,7 @@ public class TableStruct {
* @param whereFields WHERE条件 * @param whereFields WHERE条件
*/ */
private void addSaveWithSql(TableSqlCache tableStruct, String sqlName, List<TableFieldVo> whereFields) { private void addSaveWithSql(TableSqlCache tableStruct, String sqlName, List<TableFieldVo> whereFields) {
SqlData sqlData = this.releaseSql(DaoConst.SQL_TYPE_SAVE_WITH, sqlName, DaoConst.LOAD_MODEL, StringHelper.EMPTY, new ArrayList<>(), whereFields); SqlData sqlData = this.releaseSql(DaoConst.SQL_TYPE_SAVE_WITH, sqlName, DaoConst.SQL_LOAD, StringHelper.EMPTY, new ArrayList<>(), whereFields);
tableStruct.add(sqlData); tableStruct.add(sqlData);
} }
...@@ -634,9 +637,9 @@ public class TableStruct { ...@@ -634,9 +637,9 @@ public class TableStruct {
* @param updateFields 需要增加的值的字段 * @param updateFields 需要增加的值的字段
*/ */
private void addGroupSql(TableSqlCache sqlTableData, List<TableFieldVo> whereFields, List<TableFieldVo> updateFields) { private void addGroupSql(TableSqlCache sqlTableData, List<TableFieldVo> whereFields, List<TableFieldVo> updateFields) {
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_QUERY, DaoConst.LOAD_MODEL, sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_QUERY, DaoConst.SQL_LOAD,
StringHelper.EMPTY, new ArrayList<>(), whereFields)); StringHelper.EMPTY, new ArrayList<>(), whereFields));
sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.UPDATE_MODEL, sqlTableData.add(this.releaseSql(DaoConst.SQL_TYPE_ADD_GROUP, DaoConst.GROUP_ADD, DaoConst.SQL_UPDATE,
DaoConst.CODE_GROUP_ADD, updateFields, this.getFieldActionList(DaoConst.FIELD_PRIMARY))); DaoConst.CODE_GROUP_ADD, updateFields, this.getFieldActionList(DaoConst.FIELD_PRIMARY)));
} }
...@@ -648,7 +651,7 @@ public class TableStruct { ...@@ -648,7 +651,7 @@ public class TableStruct {
* @param fields 需要判断的字段 * @param fields 需要判断的字段
*/ */
public void addExist(TableSqlCache sqlTableData, String sqlName, String[] fields) { public void addExist(TableSqlCache sqlTableData, String sqlName, String[] fields) {
String text = DaoConst.LOAD_MODEL.replace(DaoConst.TABLE_CODE, this.name); String text = DaoConst.SQL_LOAD.replace(DaoConst.CODE_TABLE, this.name);
SqlData sql = new SqlData(sqlName, text); SqlData sql = new SqlData(sqlName, text);
sql.setSqlType(DaoConst.SQL_TYPE_SAVE_WITH); sql.setSqlType(DaoConst.SQL_TYPE_SAVE_WITH);
sql.addConst(this.getKey().inputName, sql.addConst(this.getKey().inputName,
......
...@@ -84,7 +84,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -84,7 +84,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
} else if (field.getGetMethod() != null) { } else if (field.getGetMethod() != null) {
annotation = field.getGetMethod().getAnnotation(TableAnnotation.class); annotation = field.getGetMethod().getAnnotation(TableAnnotation.class);
} }
if (annotation != null) { if (annotation != null && !StringHelper.isEmpty(annotation.value())) {
name = annotation.value(); name = annotation.value();
} }
String underscoredName = underscoreName(name); String underscoredName = underscoreName(name);
......
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