RoleMenuMapper.xml 2.53 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.bootdo.system.dao.RoleMenuDao">

	<select id="get" resultType="com.bootdo.system.domain.RoleMenuDO">
		select `id`,`role_id`,`menu_id` from
		sys_role_menu where id = #{value}
	</select>

	<select id="list" resultType="com.bootdo.system.domain.RoleMenuDO">
		select `id`,`role_id`,`menu_id` from sys_role_menu
		<where>
			<if test="id != null and id != ''"> and id = #{id} </if>
			<if test="roleId != null and roleId != ''"> and role_id = #{roleId} </if>
			<if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
		</where>
		<choose>
			<when test="sort != null and sort.trim() != ''">
				order by ${sort} ${order}
			</when>
			<otherwise>
				order by id desc
			</otherwise>
		</choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>

	<select id="count" resultType="int">
		select count(*) from sys_role_menu
		<where>
			<if test="id != null and id != ''"> and id = #{id} </if>
			<if test="roleId != null and roleId != ''"> and role_id = #{roleId} </if>
			<if test="menuId != null and menuId != ''"> and menu_id = #{menuId} </if>
		</where>
	</select>

	<insert id="save" parameterType="com.bootdo.system.domain.RoleMenuDO"
		useGeneratedKeys="true" keyProperty="id">
		insert into sys_role_menu
		(
		`role_id`,
		`menu_id`
		)
		values
		(
		#{roleId},
		#{menuId}
		)
	</insert>

	<update id="update" parameterType="com.bootdo.system.domain.RoleMenuDO">
		update sys_role_menu
		<set>
			<if test="roleId != null">`role_id` = #{roleId}, </if>
			<if test="menuId != null">`menu_id` = #{menuId}</if>
		</set>
		where id = #{id}
	</update>

	<delete id="remove">
		delete from sys_role_menu where id = #{value}
	</delete>

	<delete id="batchRemove">
		delete from sys_role_menu where id in
		<foreach item="id" collection="array" open="(" separator=","
			close=")">
			#{id}
		</foreach>
	</delete>

	<select id="listMenuIdByRoleId" resultType="long">
		select menu_id from sys_role_menu
		<where>role_id = #{roleId}</where>
	</select>

	<delete id="removeByRoleId">
		DELETE FROM sys_role_menu WHERE role_id=#{roleId}
	</delete>

	<delete id="removeByMenuId">
		DELETE FROM sys_role_menu WHERE menu_id=#{menuId}
	</delete>

	<insert id="batchSave">
		INSERT INTO sys_role_menu(role_id, menu_id) values
		<foreach item="item" index="index" collection="list"
			separator=",">
			(#{item.roleId},#{item.menuId})
		</foreach>
	</insert>
</mapper>