zouxuan 6 년 전
부모
커밋
8d2a2b8a3a
1개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 4
      codegen/src/main/java/com/yonge/crud/core/generator/ModuleGenerateIntrospector.java

+ 4 - 4
codegen/src/main/java/com/yonge/crud/core/generator/ModuleGenerateIntrospector.java

@@ -121,13 +121,13 @@ public class ModuleGenerateIntrospector {
 		params.put("insertSQL", insertSQL);
 		if (StringUtils.isNotBlank(criteria)) {
 			// 修改
-			String updateSQL = "UPDATE " + tableName + " SET ";
+			String updateSQL = "UPDATE " + tableName + " <set>\n<if test=\"";
 			for (Entry<String, String> entry : fieldPropMapping.entrySet()) {
-				updateSQL += (entry.getKey() + " = #{" + entry.getValue() + "},");
+				updateSQL += entry.getValue() + " != null\">\n" + (entry.getKey() + " = #{" + entry.getValue() + "},\n</if>\n<if test=\"");
 			}
 			// 删除最后一个“,”
-			updateSQL = updateSQL.substring(0, updateSQL.length() - 1);
-			updateSQL += (" WHERE " + criteria);
+			updateSQL = updateSQL.substring(0, updateSQL.length() - 10);
+			updateSQL += ("</set> WHERE " + criteria);
 			params.put("updateSQL", updateSQL);
 			// 根据主键查询
 			String querySingleSQL = queryBaseSQL + " WHERE " + criteria;