@@ -13,23 +13,33 @@ import java.util.List;
1313@Repository
1414public interface ${classInfo.className} Mapper {
1515
16- @Select("select * from ${classInfo.tableName} where ${classInfo.tableName} _id=井{id}")
17- public ${classInfo.className} getById(Integer id);
16+ @Select("""
17+ select * from ${classInfo.tableName} where ${classInfo.tableName} _id=井{id}
18+ """)
19+ public ${classInfo.className} find(Integer id);
1820
1921 @Options(useGeneratedKeys=true,keyProperty="${classInfo.className?uncap_first } Id")
20- @Insert("insert into ${classInfo.tableName} " +
21- " (<#list classInfo.fieldList as fieldItem >${fieldItem.columnName} <#if fieldItem_has_next >,</#if ></#list >)" +
22- " values(<#list classInfo.fieldList as fieldItem >${fieldItem.fieldName} <#if fieldItem_has_next >,<#else >)</#if ></#list >")
22+ @Insert("""
23+ insert into ${classInfo.tableName} (
24+ <#list classInfo.fieldList as fieldItem >${fieldItem.columnName} <#if fieldItem_has_next >,</#if ></#list >
25+ ) values (
26+ <#list classInfo.fieldList as fieldItem >井{${fieldItem.fieldName} }<#if fieldItem_has_next >,<#else >)</#if ></#list >
27+ )
28+ """)
2329 public Integer insert(${classInfo.className} ${classInfo.className?uncap_first } );
2430
25- @Delete(value = "delete from ${classInfo.tableName} where ${classInfo.tableName} _id=井{${classInfo.className?uncap_first } Id}")
31+ @Delete("""
32+ delete from ${classInfo.tableName} where ${classInfo.tableName} _id=井{id}
33+ """)
2634 boolean delete(Integer id);
2735
28- @Update(value = "update ${classInfo.tableName} set "
29- <#list classInfo.fieldList as fieldItem >
30- <#if fieldItem.columnName != "id" >+" ${fieldItem.columnName} =井{${fieldItem.fieldName} }<#if fieldItem_has_next >,</#if >"</#if >
31- </#list >
32- +" where ${classInfo.tableName} _id=井{${classInfo.className?uncap_first } Id} ")
36+ @Update("""
37+ update ${classInfo.tableName} set
38+ <#list classInfo.fieldList as fieldItem >
39+ <#if fieldItem.columnName != "id" >${fieldItem.columnName} =井{${fieldItem.fieldName} }<#if fieldItem_has_next >,</#if ></#if >
40+ </#list >
41+ where ${classInfo.tableName} _id=井{id}
42+ """)
3343 boolean update(${classInfo.className} ${classInfo.className?uncap_first } );
3444
3545
@@ -38,19 +48,73 @@ public interface ${classInfo.className}Mapper {
3848 @Result(property = "${fieldItem.fieldName} ", column = "${fieldItem.columnName} ")<#if fieldItem_has_next >,</#if >
3949 </#list >
4050 })
41- @Select(value = "select * from ${classInfo.tableName} where ${classInfo.tableName} _id=井{queryParam}")
42- ${classInfo.className} selectOne(String queryParam);
51+ @Select("""
52+ select * from ${classInfo.tableName} where ${classInfo.tableName} _id=井{id}
53+ """)
54+ ${classInfo.className} selectOne(Integer id);
4355
4456 @Results(value = {
4557 <#list classInfo.fieldList as fieldItem >
4658 @Result(property = "${fieldItem.fieldName} ", column = "${fieldItem.columnName} ")<#if fieldItem_has_next >,</#if >
4759 </#list >
4860 })
49- @Select(value = "select * from ${classInfo.tableName} where "
50- <#list classInfo.fieldList as fieldItem >
51- +" ${fieldItem.columnName} =井{${fieldItem.fieldName} }<#if fieldItem_has_next > or </#if >"
52- </#list >
53- )
61+ @Select("""
62+ select * from ${classInfo.tableName} where
63+ <#list classInfo.fieldList as fieldItem >
64+ ${fieldItem.columnName} =井{${fieldItem.fieldName} }<#if fieldItem_has_next > or </#if >
65+ </#list >
66+ """)
5467 List<${classInfo.className} > selectList(${classInfo.className} ${classInfo.className?uncap_first } );
5568
69+ /**
70+ * 动态条件分页查询 - 根据对象属性自动构建条件
71+ * 如果字段有值则进行分页+指定条件查询,否则仅进行分页查询
72+ */
73+ @Select("""
74+ <script >
75+ SELECT * FROM ${classInfo .tableName }
76+ < where>
77+ < #list classInfo .fieldList as fieldItem>
78+ < #if fieldItem .fieldClass ? contains (" String" )>
79+ < if test= ' queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""' >
80+ AND ${fieldItem .columnName } = 井{queryParamDTO .$ {fieldItem .fieldName }}
81+ < / if >
82+ < #else >
83+ < if test= ' queryParamDTO.${fieldItem.fieldName} != null' >
84+ AND ${fieldItem .columnName } = 井{queryParamDTO .$ {fieldItem .fieldName }}
85+ < / if >
86+ < / #if >
87+ < / #list>
88+ < / where>
89+ ORDER BY id DESC
90+ LIMIT 井{offset}, 井{limit}
91+ < / script>
92+ " " " )
93+ List<${classInfo.className}> pageByCondition(@Param(" queryParamDTO" ) ${classInfo.className} queryParamDTO,
94+ @Param(" offset" ) int offset,
95+ @Param(" limit" ) int limit);
96+
97+ /**
98+ * 动态条件分页查询总数
99+ */
100+ @Select(" " "
101+ < script>
102+ SELECT COUNT (* ) FROM ${classInfo .tableName }
103+ < where>
104+ < #list classInfo .fieldList as fieldItem>
105+ < #if fieldItem .fieldClass ? contains (" String" )>
106+ < if test= ' queryParamDTO.${fieldItem.fieldName} != null and queryParamDTO.${fieldItem.fieldName} != ""' >
107+ AND ${fieldItem .columnName } = 井{queryParamDTO .$ {fieldItem .fieldName }}
108+ < / if >
109+ < #else >
110+ < if test= ' queryParamDTO.${fieldItem.fieldName} != null' >
111+ AND ${fieldItem .columnName } = 井{queryParamDTO .$ {fieldItem .fieldName }}
112+ < / if >
113+ < / #if >
114+ < / #list>
115+ < / where>
116+ < / script>
117+ " " " )
118+ int pageByConditionCount(@Param(" queryParamDTO" ) ${classInfo.className} queryParamDTO);
119+
56120}
0 commit comments