<?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="im.zhaojun.system.mapper.UserRoleMapper">

    <sql id="Base_Column_List">
            `user_id`,
            `role_id`
    </sql>

    <resultMap id="BaseResultMap" type="im.zhaojun.system.model.UserRole">
        <result column="user_id" jdbcType="INTEGER" property="userId"/>
        <result column="role_id" jdbcType="INTEGER" property="roleId"/>
    </resultMap>

    <insert id="insert" parameterType="im.zhaojun.system.model.UserRole">
        insert into user_role (user_id, role_id)
        values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER})
    </insert>

    <insert id="insertList">
        insert into user_role( user_id,role_id  )values
        <foreach collection="roleIds" item="roleId" index="index" separator=",">
       (#{userId},#{roleId} )
        </foreach>
    </insert>

    <delete id="deleteUserRoleByUserId">
        delete
        from user_role
        where user_id = #{userId}
    </delete>

    <delete id="deleteUserRoleByRoleId">
        delete
        from user_role
        where role_id = #{roleId}
    </delete>

    <select id="selectUserIdByRoleId" resultType="java.lang.Integer">
        select user_id
        from user_role
        where role_id = #{roleId,jdbcType=INTEGER}
    </select>
</mapper>