ROLEMapper.xml 3.2 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.tianbo.warehouse.dao.ROLEMapper" >
  <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.ROLE" >
    <id column="ROLE_ID" property="roleId" jdbcType="DECIMAL" />
    <result column="ROLE_NAME" property="roleName" jdbcType="VARCHAR" />
    <result column="ROLE_SIGN" property="roleSign" jdbcType="VARCHAR" />
    <result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    ROLE_ID, ROLE_NAME, ROLE_SIGN, DESCRIPTION
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.math.BigDecimal" >
    select 
    <include refid="Base_Column_List" />
    from ROLE
    where ROLE_ID = #{roleId,jdbcType=DECIMAL}
  </select>
  <select id="findRolesByUserId" parameterType="java.math.BigDecimal" resultMap="BaseResultMap">
    SELECT
    R.*
    FROM
    USERS U
    LEFT JOIN USER_ROLE UR ON U .USER_ID = UR.USER_ID
    LEFT JOIN ROLE R ON  R.ROLE_ID= UR.ROLE_ID
    where U.USER_ID = #{userId,jdbcType=DECIMAL}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.math.BigDecimal" >
    delete from ROLE
    where ROLE_ID = #{roleId,jdbcType=DECIMAL}
  </delete>
  <insert id="insert" parameterType="com.tianbo.warehouse.model.ROLE" >
    insert into ROLE (ROLE_ID, ROLE_NAME, ROLE_SIGN, 
      DESCRIPTION)
    values (#{roleId,jdbcType=DECIMAL}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR}, 
      #{description,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.ROLE" >
    insert into ROLE
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="roleId != null" >
        ROLE_ID,
      </if>
      <if test="roleName != null" >
        ROLE_NAME,
      </if>
      <if test="roleSign != null" >
        ROLE_SIGN,
      </if>
      <if test="description != null" >
        DESCRIPTION,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="roleId != null" >
        #{roleId,jdbcType=DECIMAL},
      </if>
      <if test="roleName != null" >
        #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="roleSign != null" >
        #{roleSign,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        #{description,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.ROLE" >
    update ROLE
    <set >
      <if test="roleName != null" >
        ROLE_NAME = #{roleName,jdbcType=VARCHAR},
      </if>
      <if test="roleSign != null" >
        ROLE_SIGN = #{roleSign,jdbcType=VARCHAR},
      </if>
      <if test="description != null" >
        DESCRIPTION = #{description,jdbcType=VARCHAR},
      </if>
    </set>
    where ROLE_ID = #{roleId,jdbcType=DECIMAL}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.ROLE" >
    update ROLE
    set ROLE_NAME = #{roleName,jdbcType=VARCHAR},
      ROLE_SIGN = #{roleSign,jdbcType=VARCHAR},
      DESCRIPTION = #{description,jdbcType=VARCHAR}
    where ROLE_ID = #{roleId,jdbcType=DECIMAL}
  </update>
</mapper>