SysUserRoleMapper.xml 3.61 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.glsx.usercenter.mapper.SysUserRoleMapper">
    <resultMap id="BaseResultMap" type="com.glsx.usercenter.pojo.user.SysUserRole">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="user_id" jdbcType="INTEGER" property="userId"/>
        <result column="role_id" jdbcType="INTEGER" property="roleId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, user_id, role_id
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_user_role
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        DELETE FROM sys_user_role
        WHERE id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" parameterType="com.glsx.usercenter.pojo.user.SysUserRole">
        INSERT INTO sys_user_role (id, user_id, role_id
        )
        VALUES (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
        )
    </insert>
    <insert id="insertSelective" parameterType="com.glsx.usercenter.pojo.user.SysUserRole">
        insert into sys_user_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="userId != null">
                user_id,
            </if>
            <if test="roleId != null">
                role_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="userId != null">
                #{userId,jdbcType=INTEGER},
            </if>
            <if test="roleId != null">
                #{roleId,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.glsx.usercenter.pojo.user.SysUserRole">
        update sys_user_role
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=INTEGER},
            </if>
            <if test="roleId != null">
                role_id = #{roleId,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.glsx.usercenter.pojo.user.SysUserRole">
        UPDATE sys_user_role
        SET user_id = #{userId,jdbcType=INTEGER},
            role_id = #{roleId,jdbcType=INTEGER}
        WHERE id = #{id,jdbcType=INTEGER}
    </update>
    <select id="findUserRoles" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from sys_user_role
        where user_id = #{userId,jdbcType=INTEGER}
    </select>
    <delete id="deleteByUserId" parameterType="java.lang.Integer">
        DELETE FROM sys_user_role
        WHERE user_id = #{userId,jdbcType=INTEGER}
    </delete>

    <select id="getRoleByUserId" parameterType="java.lang.Integer" resultType="com.glsx.usercenter.pojo.user.SysUserRole">
        SELECT
            sr.id        roleId,
            sr.name roleName
        FROM sys_user su LEFT JOIN sys_user_role sur ON su.id = sur.user_id
            LEFT JOIN sys_role sr ON sur.role_id = sr.id
        WHERE su.id = #{id,jdbcType=TINYINT}
    </select>
</mapper>