admin
2021-10-12 664cc2fd39177fd3daa6d3988396c704d130882c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?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="${mapper.clazz}">
    <resultMap id="BaseResultMap"
               type="${entity.clazz}">
        <id column="${identify.column}" property="${identify.property}" jdbcType="${identify.jdbcType}"/>
        <#list columnList as column>
        <result column="${column.column}" property="${column.property}" jdbcType="${column.jdbcType}"/>
        </#list>
    </resultMap>
 
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
        <#list columnList as column>${column.column},</#list>
        </trim>
    </sql>
 
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
            parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from ${table} where ${identify.column} = <#noparse>#{</#noparse>id, jdbcType=${identify.jdbcType}}
    </select>
 
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
            parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from ${table} where ${identify.column} = <#noparse>#{</#noparse>id,jdbcType=${identify.jdbcType}} for update
    </select>
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from
        ${table} where ${identify.column} = <#noparse>#{</#noparse>id,jdbcType=${identify.jdbcType}}
    </delete>
    <insert id="insert"
            parameterType="${entity.class}"
            useGeneratedKeys="true" keyProperty="${identify.property}">
        insert into
        ${table}
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list columnList as column>
            ${column.column}},
        </#list>
 
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <#list columnList as column>
            <#noparse>#{</#noparse>${column.property}},jdbcType=${column.jdbcType}},
        </#list>
 
        </trim>
 
    </insert>
    <insert id="insertSelective"
            parameterType="${entity.class}"
            useGeneratedKeys="true" keyProperty="${identify.property}">
        insert into ${table}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="${identify.property} != null">${identify.column},</if>
            <#list columnList as column>
             <if test="${column.property} != null">${column.column},</if>
            </#list>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="${identify.property} != null"><#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}},</if>
            <#list columnList as column>
             <if test="${column.property} != null"><#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if>
            </#list>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
            parameterType="${entity.class}">
        update ${table}
        <set>
            <if test="${identify.property} != null">${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}},</if>
              <#list columnList as column>
                  <if test="${column.property} != null">${column.column} = <#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if>
              </#list>
        </set>
        where ${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}}
    </update>
    <update id="updateByPrimaryKeySelective"
            parameterType="${entity.class}">
        update ${table}
        <set>
              <#list columnList as column>
             <if test="${column.property} != null">${column.column} = <#noparse>#{</#noparse>${column.property},jdbcType=${column.jdbcType}},</if>
              </#list>
        </set>
        where ${identify.column} = <#noparse>#{</#noparse>${identify.property},jdbcType=${identify.jdbcType}}
    </update>
 
    <sql id="listWhere">
        <#list queryList as query>
        <if test="query.${query.columnName}!=null">
            <#if query.queryType=="equal">
                and ${query.columnData.column} = <#noparse>#{</#noparse>query.${query.columnName}}
            </#if>
             <#if query.queryType=="start">
                and ${query.columnData.column} like '<#noparse>#{</#noparse>query.${query.columnName}}%'
             </#if>
             <#if query.queryType=="end">
                and ${query.columnData.column} like '%<#noparse>#{</#noparse>query.${query.columnName}}'
             </#if>
             <#if query.queryType=="contains">
                and ${query.columnData.column} = '%<#noparse>#{</#noparse>query.${query.columnName}}%'
             </#if>
        </if>
        </#list>
    </sql>
 
    <select id="list"
            resultMap="BaseResultMap">
        SELECT * FROM  ${table}
        <where>
            <include refid="listWhere">
            </include>
        </where>
        <if test="query.sortList!=null">
            <foreach collection="query.sortList" open=" order by " separator="," item="item">
            <#noparse>#{</#noparse>item}
            </foreach>
        </if>
        limit <#noparse>#{</#noparse>query.start},<#noparse>#{</#noparse>query.count}
    </select>
 
 
    <select id="count"
            resultType="java.lang.Long">
        SELECT count(*) FROM  ${table}
        <where>
            <include refid="listWhere">
            </include>
        </where>
    </select>
 
 
</mapper>