zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    iOS 面试题 1
    ios 面试题 0
    得到程序包路径
    UISwitch 监听响应
    在[self addsubView:xxx]中,self.name 和 _name的区别
    /调整button的title的位置
    //设置导航条背景图片
    警告框
    @synthesize
    打开控制台选中路径的文件夹
  • 原文地址:https://www.cnblogs.com/LifeFruit/p/13839153.html
Copyright © 2011-2022 走看看