Mabatis通用SQL语句

通用sql语句

DAO层

1  //新增
2 Long add(@Param("tableName")String tableName, @Param("params") Map<String,Object> params);
3 //查询
4 List<Map<String,Object>> listByKeys(@Param("tableName")String tableName, @Param("params") Map<String,Object> params);
5 //修改
6 int modify(@Param("tableName")String tableName, Map<String,Object> params);

 

Mapper.xml

 1 <insert id="add" parameterType="Map">
 2         insert into ${tableName}
 3         <foreach collection="params.keys" item="key" index="index" open="(" close=")" separator=",">
 4             ${key}
 5         </foreach>
 6         values
 7         <foreach collection="params.values" item="value" index="index" open="(" close=")" separator=",">
 8             #{value}
 9         </foreach>
10     </insert>
11 
12     <select id="listByCondition" parameterType="Map" resultType="java.util.Map">
13         select * from ${tableName}
14         where 1 = 1 and
15         <foreach collection="params" index="key" item="value" separator="and">
16             ${key} = #{value}
17         </foreach>
18     </select>
19 
20     <update id="modify" parameterType="Map" >
21         update ${tableName}
22         set
23         <foreach collection="params" index="key" item="value" separator=",">
24             ${key} = #{value}
25         </foreach>
26         where id = #{params.id}
27     </update>

 

posted @ 2020-10-19 11:16  生命树gyh  阅读(89)  评论(0)    收藏  举报
© 2020 GitHub, Inc.