提交 | 用户 | 时间
|
fd2207
|
1 |
<?xml version="1.0" encoding="UTF-8" ?> |
懒 |
2 |
<!DOCTYPE mapper |
|
3 |
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|
4 |
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|
5 |
<mapper namespace="${packageName}.mapper.${ClassName}Mapper"> |
|
6 |
|
|
7 |
<resultMap type="${ClassName}" id="${ClassName}Result"> |
|
8 |
#foreach ($column in $columns) |
|
9 |
<result property="${column.javaField}" column="${column.columnName}" /> |
|
10 |
#end |
|
11 |
</resultMap> |
|
12 |
#if($table.sub) |
|
13 |
|
|
14 |
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result"> |
|
15 |
<collection property="${subclassName}List" notNullColumn="sub_${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" /> |
|
16 |
</resultMap> |
|
17 |
|
|
18 |
<resultMap type="${subClassName}" id="${subClassName}Result"> |
|
19 |
#foreach ($column in $subTable.columns) |
|
20 |
<result property="${column.javaField}" column="sub_${column.columnName}" /> |
|
21 |
#end |
|
22 |
</resultMap> |
|
23 |
#end |
|
24 |
|
|
25 |
<sql id="select${ClassName}Vo"> |
|
26 |
select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName} |
|
27 |
</sql> |
|
28 |
|
|
29 |
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result"> |
|
30 |
<include refid="select${ClassName}Vo"/> |
|
31 |
<where> |
|
32 |
#foreach($column in $columns) |
|
33 |
#set($queryType=$column.queryType) |
|
34 |
#set($javaField=$column.javaField) |
|
35 |
#set($javaType=$column.javaType) |
|
36 |
#set($columnName=$column.columnName) |
|
37 |
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
|
38 |
#if($column.query) |
|
39 |
#if($column.queryType == "EQ") |
|
40 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if> |
|
41 |
#elseif($queryType == "NE") |
|
42 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if> |
|
43 |
#elseif($queryType == "GT") |
|
44 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if> |
|
45 |
#elseif($queryType == "GTE") |
|
46 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if> |
|
47 |
#elseif($queryType == "LT") |
|
48 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if> |
|
49 |
#elseif($queryType == "LTE") |
|
50 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if> |
|
51 |
#elseif($queryType == "LIKE") |
|
52 |
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if> |
|
53 |
#elseif($queryType == "BETWEEN") |
|
54 |
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if> |
|
55 |
#end |
|
56 |
#end |
|
57 |
#end |
|
58 |
</where> |
|
59 |
</select> |
|
60 |
|
|
61 |
<select id="select${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end"> |
|
62 |
#if($table.crud || $table.tree) |
|
63 |
<include refid="select${ClassName}Vo"/> |
|
64 |
where ${pkColumn.columnName} = #{${pkColumn.javaField}} |
|
65 |
#elseif($table.sub) |
|
66 |
select#foreach($column in $columns) a.$column.columnName#if($foreach.count != $columns.size()),#end#end, |
|
67 |
#foreach($column in $subTable.columns) b.$column.columnName as sub_$column.columnName#if($foreach.count != $subTable.columns.size()),#end#end |
|
68 |
|
|
69 |
from ${tableName} a |
|
70 |
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName} |
|
71 |
where a.${pkColumn.columnName} = #{${pkColumn.javaField}} |
|
72 |
#end |
|
73 |
</select> |
|
74 |
|
|
75 |
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> |
|
76 |
insert into ${tableName} |
|
77 |
<trim prefix="(" suffix=")" suffixOverrides=","> |
|
78 |
#foreach($column in $columns) |
|
79 |
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) |
|
80 |
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if> |
|
81 |
#end |
|
82 |
#end |
|
83 |
</trim> |
|
84 |
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|
85 |
#foreach($column in $columns) |
|
86 |
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) |
|
87 |
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if> |
|
88 |
#end |
|
89 |
#end |
|
90 |
</trim> |
|
91 |
</insert> |
|
92 |
|
|
93 |
<update id="update${ClassName}" parameterType="${ClassName}"> |
|
94 |
update ${tableName} |
|
95 |
<trim prefix="SET" suffixOverrides=","> |
|
96 |
#foreach($column in $columns) |
|
97 |
#if($column.columnName != $pkColumn.columnName) |
|
98 |
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if> |
|
99 |
#end |
|
100 |
#end |
|
101 |
</trim> |
|
102 |
where ${pkColumn.columnName} = #{${pkColumn.javaField}} |
|
103 |
</update> |
|
104 |
|
|
105 |
<delete id="delete${ClassName}By${pkColumn.capJavaField}" parameterType="${pkColumn.javaType}"> |
|
106 |
delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} |
|
107 |
</delete> |
|
108 |
|
|
109 |
<delete id="delete${ClassName}By${pkColumn.capJavaField}s" parameterType="String"> |
|
110 |
delete from ${tableName} where ${pkColumn.columnName} in |
|
111 |
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")"> |
|
112 |
#{${pkColumn.javaField}} |
|
113 |
</foreach> |
|
114 |
</delete> |
|
115 |
#if($table.sub) |
|
116 |
|
|
117 |
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String"> |
|
118 |
delete from ${subTableName} where ${subTableFkName} in |
|
119 |
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")"> |
|
120 |
#{${subTableFkclassName}} |
|
121 |
</foreach> |
|
122 |
</delete> |
|
123 |
|
|
124 |
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="${pkColumn.javaType}"> |
|
125 |
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} |
|
126 |
</delete> |
|
127 |
|
|
128 |
<insert id="batch${subClassName}"> |
|
129 |
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()),#end#end) values |
|
130 |
<foreach item="item" index="index" collection="list" separator=","> |
|
131 |
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($foreach.count != $subTable.columns.size()),#end#end) |
|
132 |
</foreach> |
|
133 |
</insert> |
|
134 |
#end |
|
135 |
</mapper> |