forked from DeepBin/codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.ftl
More file actions
71 lines (63 loc) · 2.31 KB
/
function.ftl
File metadata and controls
71 lines (63 loc) · 2.31 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
<#--获取查询数据类型-->
<#function getDataType colType start>
<#if (colType=="long") > <#return "L">
<#elseif (colType=="int")><#return "N">
<#elseif (colType=="double")><#return "BD">
<#elseif (colType=="Short")><#return "SN">
<#elseif (colType=="Date" && start=="1")><#return "DL">
<#elseif (colType=="Date" && start=="0")><#return "DG">
<#else><#return "SL"></#if>
</#function>
<#--将字符串 user_id 转换为 类似userId-->
<#function convertUnderLine field>
<#if field?index_of("_")==-1>
<#return field>
</#if>
<#assign rtn><#list field?split("_") as x><#if (x_index==0)><#if x?length==1>${x?upper_case}<#else>${x?lower_case}</#if><#else>${x?lower_case?cap_first}</#if></#list></#assign>
<#return rtn>
</#function>
<#function getPk model>
<#assign rtn><#if (model.pkModel??) >${model.pkModel.columnName}<#else>"id"</#if></#assign>
<#return rtn>
</#function>
<#--获取主键类型-->
<#function getPkType model>
<#list model.columnList as col>
<#if col.isPK>
<#if (col.colType=="Integer")><#assign rtn>"Long"</#assign><#return rtn>
<#else><#assign pkType=col.colType ></#if>
</#if>
</#list>
<#assign rtn>${pkType}</#assign>
<#return rtn>
</#function>
<#--获取外键类型 没有则返回Long-->
<#function getFkType model>
<#assign fk=model.foreignKey>
<#list model.columnList as col>
<#if (col.columnName?lower_case)==(fk?lower_case)>
<#if (col.colType=="Integer")><#assign rtn>Long</#assign><#return rtn><#else><#assign rtn>${col.colType}</#assign><#return rtn></#if>
</#if>
</#list>
<#assign rtn>Long</#assign><#return rtn>
</#function>
<#function getPkVar model>
<#assign rtn><#if (model.pkModel??) ><#noparse>${</#noparse>${model.pkModel.columnName}<#noparse>}</#noparse><#else>"id"</#if></#assign>
<#return rtn>
</#function>
<#function getJdbcType dataType>
<#assign dbtype=dataType?lower_case>
<#assign rtn>
<#if dbtype?ends_with("int") || (dbtype=="double") || (dbtype=="float") || (dbtype=="decimal") || dbtype?ends_with("number")||dbtype?starts_with("numeric") >
NUMERIC
<#elseif (dbtype?index_of("char")>-1) >
VARCHAR
<#elseif (dbtype=="date")>
DATE
<#elseif (dbtype?index_of("timestamp")>-1) || (dbtype=="datetime") >
TIMESTAMP
<#elseif (dbtype?ends_with("text") || dbtype?ends_with("clob")) >
CLOB
</#if></#assign>
<#return rtn?trim>
</#function>