mybatis-xml增删改查

2020-08-04  本文已影响0人  jiahzhon
  <select id="selectById" resultType="io.zjh.modules.sys.entity.SysMenuEntity">
  select * from sys_menu t where t.menu_id = #{menuId}
 </select>
 <select id="findMenuName" resultType="java.lang.String" parameterType="java.util.List">
    select menu_name
    from menu
    where menu_id in
  <foreach collection="list" item="valueList" open="(" close=")" separator=",">
    #{valueList}
  </foreach>
</select>
<insert id="insert" parameterType="io.zjh.modules.sys.entity.SysMenuEntity">
  insert into sys_menu(menu_id,parent_id,name,url,perms,type,icon,order_num)
  values (
   #{menuId},
   #{parentId},
   #{name},
   #{url},
   #{perms},
   #{type},
   #{icon},
   #{orderNum}
  )
 </insert>
 <insert id="insertBatch" parameterType="java.util.List">
  insert into sys_role_menu(role_id,menu_id)
  values
  <foreach collection="list" item="item"  index="index" separator=",">
   (
   #{item.roleId},
   #{item.menuId}
   )
  </foreach>
 </insert>
 <update id="update" parameterType="io.zjh.modules.sys.entity.SysUserEntity">
  update sys_user
  <set>
   password = #{newPassword}
  </set>
  where user_id = #{userId} and password = #{password}
 </update>
<update id="updateRoles" parameterType="java.util.List">
  update role
  set enabled = '0'
  where role_id in <foreach collection="list" item="roleIds" index="index" open="(" separator="," close=")"> 
    #{roleIds} 
  </foreach>
</update>
<delete id="deleteByMenuId">
  delete from sys_role_menu where menu_id = #{menuId}
</delete>
<delete id="deleteBatchIds"  parameterType="java.util.List">
  delete from sys_user where user_id in
  <foreach collection="list" item="item"  index="index" separator="," open="(" close=")">
   #{item}
  </foreach>
</delete>

传入list和array比较

<foreach item="item" collection="array" open="(" separator="," close=")">
            #{item}
</foreach>

jdbcType

JdbcType Oracle MySql
JdbcType BIGINT BIGINT
JdbcType BIT BIT
JdbcType BLOB BLOB BLOB
JdbcType BOOLEAN
JdbcType CHAR CHAR CHAR
JdbcType CLOB CLOB 修改为TEXT
JdbcType DATE DATE DATE
JdbcType DECIMAL DECIMAL DECIMAL
JdbcType DOUBLE NUMBER DOUBLE
JdbcType FLOAT FLOAT FLOAT
JdbcType INTEGER INTEGER INTEGER
JdbcType LONGVARCHAR LONG VARCHAR
JdbcType NULL
JdbcType SMALLINT SMALLINT SMALLINT
JdbcType TIME TIME
JdbcType TIMESTAMP TIMESTAMP TIMESTAMP/DATETIME
JdbcType TINYINT TINYINT
JdbcType VARCHAR VARCHAR VARCHAR
上一篇 下一篇

猜你喜欢

热点阅读