utils.ftl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <#---->
  2. <#-- freemarker 的一些工具方法 -->
  3. <#---->
  4. <#-- 驼峰转其他字符 -->
  5. <#-- @param str 待转换的文本 -->
  6. <#-- @param character 要转换成的字符 -->
  7. <#-- @param case 转换大小写(normal 不转换,lower 小写,upper 大写) -->
  8. <#function camelToChar(str, character, case='normal')>
  9. <#assign text=str?replace("([a-z])([A-Z]+)","$1${character}$2","r")/>
  10. <#if case=="upper">
  11. <#return text?upper_case>
  12. <#elseif case=="lower">
  13. <#return text?lower_case>
  14. <#else>
  15. <#return text>
  16. </#if>
  17. </#function>
  18. <#---->
  19. <#-- 驼峰转下划线 -->
  20. <#function camelToDashed(str, case='normal')>
  21. <#return camelToChar(str, "_", case)>
  22. </#function>
  23. <#---->
  24. <#-- 驼峰转横线 -->
  25. <#function camelToHorizontal(str, case='normal')>
  26. <#return camelToChar(str, "-", case)>
  27. </#function>
  28. <#---->
  29. <#-- 获取 v-model 属性 -->
  30. <#function getVModel po,suffix="">
  31. <#return "v-model=\"queryParam.${po.fieldName}${suffix}\"">
  32. </#function>
  33. <#-- 获取 placeholder 属性 -->
  34. <#function getPlaceholder po,prefix,fillComment=true>
  35. <#if fillComment>
  36. <#return "placeholder=\"${prefix}${po.filedComment}\"">
  37. <#else>
  38. <#return "placeholder=\"${prefix}\"">
  39. </#if>
  40. </#function>
  41. <#-- ** 判断某字段是否配置了校验 * -->
  42. <#function poHasCheck po>
  43. <#if (po.fieldValidType!'')?trim?length gt 0 || po.nullable == 'N'>
  44. <#if po.fieldName != 'id'>
  45. <#if po.nullable == 'N'
  46. || po.fieldValidType == '*'
  47. || po.fieldValidType == 'only'
  48. || po.fieldValidType == 'n6-16'
  49. || po.fieldValidType == '*6-16'
  50. || po.fieldValidType == 's6-18'
  51. || po.fieldValidType == 'url'
  52. || po.fieldValidType == 'e'
  53. || po.fieldValidType == 'm'
  54. || po.fieldValidType == 'p'
  55. || po.fieldValidType == 's'
  56. || po.fieldValidType == 'n'
  57. || po.fieldValidType == 'z'
  58. || po.fieldValidType == 'money'
  59. >
  60. <#return true>
  61. </#if>
  62. </#if>
  63. </#if>
  64. <#return false>
  65. </#function>
  66. <#-- ** 如果配置了校验就显示 validatorRules * -->
  67. <#function autoWriteRules po>
  68. <#if poHasCheck(po)>
  69. <#return ", validatorRules.${po.fieldName}">
  70. <#else>
  71. <#return "">
  72. </#if>
  73. </#function>