ZhuDongming
2019-10-09 578e49d67183d8d12a6af7e8244a9d152cb366d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?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.moral.mapper.AccountRoleMapper">
 
    <resultMap id="ResultMap" type="com.moral.entity.AccountRole" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="account_id" property="accountId" jdbcType="INTEGER" />
        <result column="role_id" property="roleId" jdbcType="INTEGER" />
    </resultMap>
 
    <resultMap id="BaseResultMap" type="com.moral.entity.AccountRole" extends="ResultMap">
        <association property="account" javaType="com.moral.entity.Account">
            <result column="account_id" jdbcType="INTEGER" property="id" />
            <result column="account_name" jdbcType="VARCHAR" property="accountName" />
        </association>
        <association property="role" javaType="com.moral.entity.Role">
            <result column="role_id" property="id" jdbcType="INTEGER" />
            <result column="role_name" property="roleName" jdbcType="VARCHAR" />
        </association>
    </resultMap>
 
    <sql id="Example_Where_Clause" >
        <where >
            <foreach collection="oredCriteria" item="criteria" separator="or" >
                <if test="criteria.valid" >
                    <trim prefix="(" suffix=")" prefixOverrides="and" >
                        <foreach collection="criteria.criteria" item="criterion" >
                            <choose >
                                <when test="criterion.noValue" >
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue" >
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue" >
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue" >
                                    and ${criterion.condition}
                                    <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
 
    <select id="getAccountRoleList" resultMap="BaseResultMap">
        select
        ar.*,
        a.account_name,
        r.role_name
        from account_role ar
        left join account a on ar.account_id = a.id
        left join role r on ar.role_id = r.id
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
 
    <update id="updateByPrimaryKey" parameterType="com.moral.entity.AccountRole" >
        update account_role
        set account_id = #{accountId,jdbcType=INTEGER},
        role_id = #{roleId,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>
 
    <delete id="deleteByPrimaryKeyOwn" parameterType="java.lang.Integer" >
        delete from account_role
        where id = #{id,jdbcType=INTEGER}
    </delete>
 
</mapper>