审查视图

src/main/resources/mapping/ROLEMapper.xml 3.3 KB
1 2 3 4 5 6 7 8
<?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" jdbcType="INTEGER" property="roleId" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
    <result column="role_sign" jdbcType="VARCHAR" property="roleSign" />
    <result column="description" jdbcType="VARCHAR" property="description" />
朱兆平 authored
9
  </resultMap>
10 11
  <sql id="Base_Column_List">
    role_id, role_name, role_sign, description
朱兆平 authored
12
  </sql>
13
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
朱兆平 authored
14 15
    select 
    <include refid="Base_Column_List" />
16 17
    from role
    where role_id = #{roleId,jdbcType=INTEGER}
朱兆平 authored
18
  </select>
19 20 21 22 23
  <select id="findAll" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from role
  </select>
24
  <select id="findRolesByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
朱兆平 authored
25 26 27 28 29 30
    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
31
    where U.USER_ID = #{userId,jdbcType=INTEGER}
朱兆平 authored
32
  </select>
33 34 35
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from role
    where role_id = #{roleId,jdbcType=INTEGER}
朱兆平 authored
36
  </delete>
37 38 39 40
  <insert id="insert" parameterType="com.tianbo.warehouse.model.ROLE">
    insert into role (role_id, role_name, role_sign, 
      description)
    values (#{roleId,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR}, 
朱兆平 authored
41 42
      #{description,jdbcType=VARCHAR})
  </insert>
43 44 45 46 47
  <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.ROLE">
    insert into role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="roleId != null">
        role_id,
朱兆平 authored
48
      </if>
49 50
      <if test="roleName != null">
        role_name,
朱兆平 authored
51
      </if>
52 53
      <if test="roleSign != null">
        role_sign,
朱兆平 authored
54
      </if>
55 56
      <if test="description != null">
        description,
朱兆平 authored
57 58
      </if>
    </trim>
59 60 61
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="roleId != null">
        #{roleId,jdbcType=INTEGER},
朱兆平 authored
62
      </if>
63
      <if test="roleName != null">
朱兆平 authored
64 65
        #{roleName,jdbcType=VARCHAR},
      </if>
66
      <if test="roleSign != null">
朱兆平 authored
67 68
        #{roleSign,jdbcType=VARCHAR},
      </if>
69
      <if test="description != null">
朱兆平 authored
70 71 72 73
        #{description,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
74 75 76 77 78
  <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.ROLE">
    update role
    <set>
      <if test="roleName != null">
        role_name = #{roleName,jdbcType=VARCHAR},
朱兆平 authored
79
      </if>
80 81
      <if test="roleSign != null">
        role_sign = #{roleSign,jdbcType=VARCHAR},
朱兆平 authored
82
      </if>
83 84
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
朱兆平 authored
85 86
      </if>
    </set>
87
    where role_id = #{roleId,jdbcType=INTEGER}
朱兆平 authored
88
  </update>
89 90 91 92 93 94
  <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=INTEGER}
朱兆平 authored
95 96
  </update>
</mapper>