Mapper.xml.vm
3.06 KB
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
<?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="${packageName}.mapper.${ClassName}Mapper">
<resultMap type="${packageName}.domain.${ClassName}" id="${className}Result">
#foreach ($column in $columns)
<result property="${column.columnName}" column="${column.columnName}" />
#end
</resultMap>
##
<sql id="select${className}Vo">
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
</sql>
##
## <select id="select${className}List" parameterType="${className}" resultMap="${className}Result">
## <include refid="select${className}Vo"/>
## <where>
###foreach($column in $columns)
## <if test="$column.attrname != null and $column.attrname.trim() != ''"> and $column.columnName = #{$column.attrname}</if>
## #end
## </where>
## </select>
##
## <select id="select${className}ById" parameterType="${primaryKey.attrType}" resultMap="${className}Result">
## <include refid="select${className}Vo"/>
## where ${primaryKey.columnName} = #{${primaryKey.attrname}}
## </select>
##
## <insert id="insert${className}" parameterType="${className}"#if($primaryKey.extra == 'auto_increment') useGeneratedKeys="true" keyProperty="$primaryKey.attrname"#end>
## insert into ${tableName}
## <trim prefix="(" suffix=")" suffixOverrides=",">
###foreach($column in $columns)
###if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
## <if test="$column.attrname != null and $column.attrname != '' ">$column.columnName,</if>
###end
###end
## </trim>
## <trim prefix="values (" suffix=")" suffixOverrides=",">
###foreach($column in $columns)
###if($column.columnName != $primaryKey.columnName || $primaryKey.extra != 'auto_increment')
## <if test="$column.attrname != null and $column.attrname != ''">#{$column.attrname},</if>
###end
###end
## </trim>
## </insert>
##
## <update id="update${className}" parameterType="${className}">
## update ${tableName}
## <trim prefix="SET" suffixOverrides=",">
###foreach($column in $columns)
###if($column.columnName != $primaryKey.columnName)
## <if test="$column.attrname != null #if($column.attrType == 'String' ) and $column.attrname != '' #end ">$column.columnName = #{$column.attrname},</if>
###end
###end
## </trim>
## where ${primaryKey.columnName} = #{${primaryKey.attrname}}
## </update>
##
## <delete id="delete${className}ById" parameterType="${primaryKey.attrType}">
## delete from ${tableName} where ${primaryKey.columnName} = #{${primaryKey.attrname}}
## </delete>
##
## <delete id="delete${className}ByIds" parameterType="String">
## delete from ${tableName} where ${primaryKey.columnName} in
## <foreach item="${primaryKey.attrname}" collection="array" open="(" separator="," close=")">
## #{${primaryKey.attrname}}
## </foreach>
## </delete>
</mapper>