velocity.mdc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ---
  2. description:
  3. globs:
  4. alwaysApply: true
  5. ---
  6. # Velocity Templates in CGTM
  7. This rule explains how Velocity templates are used for code generation in this project.
  8. ## Basic Structure
  9. Velocity templates use a simple syntax with variables, directives, and references:
  10. - Variables start with `$` (e.g., `$ClassName`)
  11. - Directives start with `#` (e.g., `#foreach`, `#if`, `#end`)
  12. - Comments use `##`
  13. ## Entity Template Example
  14. ```java
  15. public class ${ClassName}Entity extends Model<${ClassName}Entity> {
  16. #foreach ($field in $fieldList)
  17. #if($field.primaryPk)
  18. @TableId(type = IdType.ASSIGN_ID)
  19. #end
  20. @Schema(description="$comment"#if($field.hidden),hidden=$field.hidden#end)
  21. private $field.attrType $field.attrName;
  22. #end
  23. }
  24. ```
  25. ## Available Context Variables
  26. ### Template Basic Properties
  27. | Variable | Description |
  28. |----------|-------------|
  29. | dbType | Database type |
  30. | package | Package name |
  31. | packagePath | Package path |
  32. | version | Version |
  33. | moduleName | Module name |
  34. | ModuleName | Module name (first letter capitalized) |
  35. | functionName | Function name |
  36. | FunctionName | Function name (first letter capitalized) |
  37. | formLayout | Form layout |
  38. | style | Style, corresponding template group |
  39. | author | Author |
  40. | datetime | Current date and time |
  41. | date | Current date |
  42. | importList | Import list |
  43. | tableName | Database table name |
  44. | tableComment | Database table comment |
  45. | className | Class name in lowercase |
  46. | ClassName | Class name |
  47. | fieldList | Field list |
  48. | backendPath | Backend path |
  49. | frontendPath | Frontend path |
  50. | childFieldList | Child table field list |
  51. | childTableName | Child table name |
  52. | mainField | Main table relation field name |
  53. | childField | Child table relation field name |
  54. | ChildClassName | Child class name (first letter capitalized) |
  55. | childClassName | Child class name in lowercase |
  56. | primaryList | Primary key field list |
  57. | formList | Form field list |
  58. | gridList | Grid field list |
  59. | queryList | Query field list |
  60. | pk | Primary key field |
  61. ### Template Field Properties
  62. | Variable | Description |
  63. |----------|-------------|
  64. | dsName | Data source name |
  65. | tableName | Table name |
  66. | fieldName | SQL field name |
  67. | fieldType | SQL field type |
  68. | attrName | Java attribute name |
  69. | attrType | Java attribute type |
  70. | fieldComment | Field description |
  71. | sort | Sort |
  72. | packageName | Attribute package name |
  73. | autoFill | Auto fill |
  74. | primaryPk | Whether it's a primary key |
  75. | baseField | Whether it's a base class field |
  76. | formItem | Whether it's a form item |
  77. | formRequired | Form required |
  78. | formType | Form type |
  79. | formValidator | Form validator |
  80. | gridItem | Whether it's a list item |
  81. | gridSort | List sorting |
  82. | queryItem | Whether it's a query item |
  83. | queryType | Query method |
  84. | queryFormType | Query form type |
  85. | fieldDict | Field dictionary type |
  86. ### Environment Variables
  87. | Variable | Description |
  88. |----------|-------------|
  89. | isSpringBoot3 | Whether it's SpringBoot 3 |
  90. | isTenant | Whether multi-tenant is supported |