代码生成
This commit is contained in:
261
doc/模版.md
Normal file
261
doc/模版.md
Normal file
@@ -0,0 +1,261 @@
|
||||
# stringtemplate4
|
||||
|
||||
设置 $
|
||||
|
||||
```
|
||||
STGroup group = new STGroupString("db_template",template, '$', '$');
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 模版的定义
|
||||
|
||||
|
||||
|
||||
基础
|
||||
|
||||
```
|
||||
classTemplate(item, module, operationList, className) ::= <<
|
||||
>>
|
||||
```
|
||||
|
||||
> 注意 <<内容>> 定义的方法
|
||||
>
|
||||
> classTemplate 为 group.getInstanceOf("classTemplate"); 定义
|
||||
|
||||
例子:
|
||||
|
||||
```java
|
||||
classTemplate(item, module, operationList, className) ::= <<
|
||||
package $module.packageName$;
|
||||
/**
|
||||
* @author xia
|
||||
* @date 2026/1/10
|
||||
* @version 0.0.1
|
||||
*/
|
||||
public class $className$ {
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
映射字典
|
||||
|
||||
```ts
|
||||
// 定义一个映射字典
|
||||
requestAnnotations ::= [
|
||||
"POST": "@PostMapping",
|
||||
"GET": "@GetMapping",
|
||||
"PUT": "@PutMapping",
|
||||
"DELETE": "@DeleteMapping",
|
||||
default: "@RequestMapping"
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Controller
|
||||
|
||||
|
||||
|
||||
```java
|
||||
requestAnnotations ::= [
|
||||
"POST": "@PostMapping",
|
||||
"GET": "@GetMapping",
|
||||
"PUT": "@PutMapping",
|
||||
"DELETE": "@DeleteMapping",
|
||||
default: "@RequestMapping"
|
||||
]
|
||||
|
||||
classTemplate(module,item,operationList,basics) ::= <<
|
||||
package $module.packageName$.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* $item.itemName$ 控制器
|
||||
* @author xia
|
||||
*/
|
||||
@Tag(name = "$item.itemName$")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/$item.itemCode$")
|
||||
public class $basics.itemCodeUp$Controller {
|
||||
|
||||
private final $basics.itemCodeUp$Service $item.itemCode$Service;
|
||||
|
||||
$operationList:{op |
|
||||
|
||||
@OperLog
|
||||
@SecureAudit(id = $op.id$,$if(op.isGreenLight)$isGreenLight = true,$endif$ $if(!op.isTenant)$isTenant = false,$endif$
|
||||
funType = FunTypeEnum.$op.funType$, funName = "$op.funName$", funCode = "$module.moduleCode$:$item.itemCode$:$op.operationCode$")
|
||||
@Operation(summary = "$op.funName$", description = "$op.describe$")
|
||||
$requestAnnotations.(op.requestType)$("$op.url$$op.pathParamsUrl$")
|
||||
public XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$@RequestBody @Valid $basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$op.pathParamsLong$) {
|
||||
return $item.itemCode$Service.$op.methodName$($if(op.isPathParams)$$op.pathParams$$endif$$if(op.isReqParams)$req$endif$);
|
||||
\}
|
||||
|
||||
}$
|
||||
|
||||
}
|
||||
>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 请求参数
|
||||
|
||||
|
||||
|
||||
```java
|
||||
classTemplate(module,item,operationList,basics) ::= <<
|
||||
package $module.apiPackageName$.request.$item.itemCode$;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* $item.itemName$
|
||||
* $basics.oper.funName$ 请求参数
|
||||
* @author xia
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "$basics.oper.funName$ 参数")
|
||||
public class $basics.itemCodeUp$Req $if(basics.oper.isPage)$extends XhPage$endif$ implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
||||
}
|
||||
>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 响应参数
|
||||
|
||||
|
||||
|
||||
```java
|
||||
classTemplate(module,item,operationList,basics) ::= <<
|
||||
package $module.apiPackageName$.response.$item.itemCode$;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* $item.itemName$
|
||||
* $basics.oper.funName$ 响应
|
||||
* @author xia
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "$basics.oper.funName$ 响应")
|
||||
public class $basics.itemCodeUp$Res implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
||||
}
|
||||
>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 服务接口
|
||||
|
||||
|
||||
|
||||
```java
|
||||
classTemplate(module,item,operationList,basics) ::= <<
|
||||
package $module.packageName$.service;
|
||||
|
||||
/**
|
||||
* $item.itemName$ 服务层接口
|
||||
* @author xia
|
||||
*/
|
||||
public interface $basics.itemCodeUp$Service {
|
||||
|
||||
$operationList:{op |
|
||||
|
||||
/**
|
||||
* $op.funName$
|
||||
* $op.describe$
|
||||
*/
|
||||
XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$if(op.isPathParams)$$op.pathParamsLongReq$$endif$);
|
||||
|
||||
}$
|
||||
|
||||
}
|
||||
>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 服务接口实现
|
||||
|
||||
|
||||
|
||||
```java
|
||||
classTemplate(module,item,operationList,basics) ::= <<
|
||||
package $module.packageName$.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import $module.packageName$.service.$basics.itemCodeUp$Service;
|
||||
|
||||
/**
|
||||
* $item.itemName$ 服务层接口
|
||||
* @author xia
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class $basics.itemCodeUp$ServiceImpl implements $basics.itemCodeUp$Service{
|
||||
|
||||
$operationList:{op |
|
||||
|
||||
/**
|
||||
* $op.funName$
|
||||
* $op.describe$
|
||||
*/
|
||||
@Override
|
||||
public XResult<$if(op.isPage)$Page<$basics.itemCodeUp$$op.methodNamePascalCase$Res>$else$$if(op.isResParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Res$else$Void$endif$$endif$> $op.methodName$($if(op.isReqParams)$$basics.itemCodeUp$$op.methodNamePascalCase$Req req$endif$$if(op.isPathParams)$$op.pathParamsLongReq$$endif$){
|
||||
// TODO $op.funName$ 实现
|
||||
return null;
|
||||
\}
|
||||
|
||||
}$
|
||||
|
||||
}
|
||||
>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user