V1ControllerTemplate.ftl
3.95 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package ${basePackage}.controller.v1;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import ${basePackage}.bean.entity.${entityClassSimpleName};
import ${basePackage}.constants.GlobalConstants;
import ${basePackage}.service.${serviceClassSimpleName};
import com.taover.util.UtilHttpRequestMap;
import com.taover.util.bean.ResultInfo;
import com.taover.util.bean.UtilResultInfo;
@RestController("v1.${controllerMap}")
@RequestMapping("/v1/${controllerMap}")
public class ${controllerClassName} {
@Resource
private ${serviceClassSimpleName} ${serviceClassFieldName};
/**
* @apiDefine ResultInfo
* @apiSuccess {string}
* @apiSuccessExample {json} Success-Response:
* {
* code:ok,
* error:null
* }
* @apiError ThrowException 出现异常
* @apiErrorExample
* {
* code:fail,
* error:null exception
* }
*/
/**
* @api {GET} /v1/${controllerMap} 查询${controllerMap}列表
* @apiDescription 查询${controllerMap}列表数据
* 返回分页结果
*
* @apiGroup ${controllerMap}
* @apiName ${controllerMap}列表
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@GetMapping
public ResultInfo get(HttpServletRequest request){
String pageStr = request.getParameter("page");
if(StringUtils.isEmpty(pageStr)){
pageStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE;
}
String sizeStr = request.getParameter("size");
if(StringUtils.isEmpty(sizeStr)){
sizeStr = ""+GlobalConstants.DEFAULT_QUERY_PAGE_SIZE;
}
List<Object[]> condition = UtilHttpRequestMap.getSqlConditionListByRequestMap(request.getParameterMap(), ${entityClassSimpleName}.class, "page,size");
return this.${serviceClassFieldName}.getListV1(condition, Integer.valueOf(pageStr), Integer.valueOf(sizeStr));
}
/**
* @api {GET} /v1/${controllerMap}/{id} 查询ssid对应的${controllerMap}
* @apiDescription 查询ssid对应${controllerMap}数据
*
* @apiGroup ${controllerMap}
* @apiName get实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@GetMapping("/{id}")
public ResultInfo get(@PathVariable Integer id){
return this.${serviceClassFieldName}.getOneV1(id);
}
/**
* @api {POST} /v1/${controllerMap} 创建${controllerMap}
* @apiDescription 创建${controllerMap}
*
* @apiGroup ${controllerMap}
* @apiName get实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@PostMapping
public ResultInfo post(HttpServletRequest request){
return UtilResultInfo.getFailure("没有找到对应处理逻辑");
}
/**
* @api {DELETE} /v1/${controllerMap}/{id} 删除id对应的${controllerMap}
* @apiDescription 删除ssid对应的${controllerMap}数据
*
* @apiGroup ${controllerMap}
* @apiName 删除实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@DeleteMapping("/{id}")
public ResultInfo delete(@PathVariable Integer id){
return UtilResultInfo.getFailure("没有找到对应处理逻辑");
}
/**
* @api {PUT} /v1/${controllerMap}/{id} 修改${controllerMap}数据
* @apiDescription 修改${controllerMap}数据
*
* @apiGroup ${controllerMap}
* @apiName 修改实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@PutMapping("/{id}")
public ResultInfo put(@PathVariable Integer id, HttpServletRequest request){
return UtilResultInfo.getFailure("没有找到对应处理逻辑");
}
}