-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Controller.vm
106 lines (98 loc) · 4.15 KB
/
Controller.vm
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#if(!$package.isEmpty())
package $package;
#end
#set($useSwaggerUI = $tablesConfig.isUseSwaggerUIComment())
#set($useJPA = $tablesConfig.isUseJpa())
#set($useMybatisPlus = $tablesConfig.isUseMybatisPlus())
#set($useTkMybatis = $tablesConfig.isUseTkMybatis())
#if($useSwaggerUI)
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
#end
import $stringHelper.getJakartaEEClassNameOrNot($useJakartaEE, "Valid");
import $stringHelper.getJakartaEEClassNameOrNot($useJakartaEE, "NotNull");
#if(!$tablesConfig.servicePackageName.isEmpty())
import ${tablesConfig.servicePackageName}.${table.serviceName};
#end
#if(!$tablesConfig.voPackageName.isEmpty())
import ${tablesConfig.voPackageName}.${entitySimpleName}${tablesConfig.voSuffixName};
import ${tablesConfig.voPackageName}.${entitySimpleName}Update${tablesConfig.voSuffixName};
import ${tablesConfig.voPackageName}.${entitySimpleName}Query${tablesConfig.voSuffixName};
#end
#if(!$tablesConfig.dtoPackageName.isEmpty())
import ${tablesConfig.dtoPackageName}.${entitySimpleName}${tablesConfig.dtoSuffixName};
#end
import org.springframework.beans.factory.annotation.Autowired;
#if($useJPA)
import org.springframework.data.domain.Page;
#end
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#if($useMybatisPlus)
import com.baomidou.mybatisplus.core.metadata.IPage;
#end
#if($useTkMybatis)
import import com.github.pagehelper.Page;
#end
#if($useSwaggerUI)
@Api(tags = "$comment")
#end
@Validated
@RestController
@RequestMapping("/$basePath")
public class ${simpleName} {
@Autowired
private $serviceName $serviceVariableName;
@PostMapping
#if($useSwaggerUI)
@ApiOperation("$save $comment")
#end
public String save(@Valid @RequestBody ${entitySimpleName}${tablesConfig.voSuffixName} ${tablesConfig.voSuffixVariableName}) {
return ${serviceVariableName}.save(${tablesConfig.voSuffixVariableName}).toString();
}
@DeleteMapping("/{id}")
#if($useSwaggerUI)
@ApiOperation("$delete $comment")
#end
public void delete(@Valid @NotNull #if($useLombok)@ApiParam("id")#end @PathVariable("id") $primaryKeyDataType id) {
${serviceVariableName}.delete(id);
}
@PutMapping("/{id}")
#if($useSwaggerUI)
@ApiOperation("$update $comment")
#end
public void update(@Valid @NotNull #if($useLombok)@ApiParam("id")#end @PathVariable("id") $primaryKeyDataType id,
@Valid @RequestBody ${entitySimpleName}Update${tablesConfig.voSuffixName} ${tablesConfig.voSuffixVariableName}) {
${serviceVariableName}.update(id, ${tablesConfig.voSuffixVariableName});
}
@GetMapping("/{id}")
#if($useSwaggerUI)
@ApiOperation("$getById $comment")
#end
public ${entitySimpleName}${tablesConfig.dtoSuffixName} getById(@Valid @NotNull #if($useLombok)@ApiParam("id")#end @PathVariable("id") $primaryKeyDataType id) {
return ${serviceVariableName}.getById(id);
}
@GetMapping
#if($useSwaggerUI)
@ApiOperation("$query $comment")
#end
#if($useJPA)
public Page<${entitySimpleName}${tablesConfig.dtoSuffixName}> query(@Valid ${entitySimpleName}Query${tablesConfig.voSuffixName} ${tablesConfig.voSuffixVariableName}) {
#end
#if($useMybatisPlus)
public IPage<${entitySimpleName}${tablesConfig.dtoSuffixName}> query(@Valid ${entitySimpleName}Query${tablesConfig.voSuffixName} ${tablesConfig.voSuffixVariableName}) {
#end
#if($useTkMybatis)
public Page<${entitySimpleName}${tablesConfig.dtoSuffixName}> query(@Valid ${entitySimpleName}Query${tablesConfig.voSuffixName} ${tablesConfig.voSuffixVariableName}) {
#end
return ${serviceVariableName}.query(${tablesConfig.voSuffixVariableName});
}
}