forked from DeepBin/codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapping.ftl
More file actions
88 lines (80 loc) · 3.02 KB
/
mapping.ftl
File metadata and controls
88 lines (80 loc) · 3.02 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<#import "function.ftl" as func>
<#assign package=model.variables.package>
<#assign class=model.variables.class>
<#assign system=vars.system>
<#assign type="com.hotent."+system+"."+package+".model.Default" +class>
<#assign tableName=model.tableName>
<#assign system=vars.system>
<#assign foreignKey=model.foreignKey>
<#assign sub=model.sub>
<#assign colList=model.columnList>
<#assign commonList=model.commonList>
<#assign pk=func.getPk(model) >
<#assign pkVar=func.getPkVar(model) >
<#-- 模板开始 -->
<?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="${type}">
<resultMap id="${class}" type="${type}">
<#list colList as col>
<#assign colName=func.convertUnderLine(col.columnName)>
<#if (col.isPK) >
<id property="${colName}" column="${col.columnName}" jdbcType="${func.getJdbcType(col.colDbType)}"/>
<#else>
<result property="${colName}" column="${col.columnName}" jdbcType="${func.getJdbcType(col.colDbType)}"/>
</#if>
</#list>
</resultMap>
<insert id="create" parameterType="${type}">
INSERT INTO ${tableName}
(<#list colList as col>${col.columnName}<#if col_has_next>,</#if></#list>)
VALUES
(<#list colList as col><#assign colName=func.convertUnderLine(col.columnName)><#noparse>#{</#noparse>${colName},jdbcType=${func.getJdbcType(col.colDbType)}<#noparse>}</#noparse><#if col_has_next>, </#if></#list>)
</insert>
<select id="get" parameterType="java.lang.String" resultMap="${class}">
SELECT * FROM ${tableName}
WHERE
${pk}=<#noparse>#{</#noparse>${func.convertUnderLine(pk)}}
</select>
<select id="query" parameterType="java.util.Map" resultMap="${class}">
SELECT * FROM ${tableName}
<where>
<if test="whereSql!=null">
<#noparse>${</#noparse>whereSql}
</if>
</where>
<if test="orderBySql!=null">
ORDER BY <#noparse>${</#noparse>orderBySql}
</if>
<if test="orderBySql==null">
ORDER BY ${pk} DESC
</if>
</select>
<update id="update" parameterType="${type}">
UPDATE ${tableName} SET
<#list commonList as col>
<#assign colName=func.convertUnderLine(col.columnName)>
${col.columnName}=<#noparse>#{</#noparse>${colName},jdbcType=${func.getJdbcType(col.colDbType)}<#noparse>}</#noparse><#if col_has_next>,</#if>
</#list>
WHERE
${pk}=<#noparse>#{</#noparse>${func.convertUnderLine(pk)}}
</update>
<delete id="remove" parameterType="java.lang.String">
DELETE FROM ${tableName}
WHERE
${pk}=<#noparse>#{</#noparse>${func.convertUnderLine(pk)}}
</delete>
<#if sub?exists && sub==true>
<#assign foreignKeyVar=func.convertUnderLine(foreignKey)>
<delete id="delByMainId">
DELETE FROM ${tableName}
WHERE
${foreignKey}=<#noparse>#{</#noparse>${foreignKeyVar}}
</delete>
<select id="get${class}List" resultMap="${class}">
SELECT *
FROM ${tableName}
WHERE ${foreignKey}=<#noparse>#{</#noparse>${foreignKeyVar}}
</select>
</#if>
</mapper>