controller.java.ftl
2.8 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
package ${package.Controller};
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
/**
* ${table.comment!} 前端控制器
*
<#if cfg.companyName??>
* @company ${cfg.companyName}
</#if>
* @author ${author}
<#if cfg.authorEmail??>
* @email ${cfg.authorEmail}
</#if>
* @since ${date}
*/
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/v1/")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass}<${table.serviceName}, ${entity}> {
<#else>
public class ${table.controllerName} {
</#if>
<#if cfg.type != "querySqldef">
/**
* 根据id获取${table.comment!}数据详情
* @param id
* @return
* @throws Exception
* ModelAndView
*/
@GetMapping(value="/getDetail")
@ApiOperation(value="根据id获取${table.comment!}数据详情",httpMethod = "GET",notes = "根据id获取${table.comment!}数据详情")
public CommonResult<${entity}> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
return CommonResult.<${entity}>ok().value(baseService.getDetail(id));
}
/**
* 新增,更新${table.comment!}
* @param ${entity?uncap_first}
* @throws Exception
* @return
* @exception
*/
@PostMapping(value="/save")
@ApiOperation(value = "新增,更新${table.comment!}数据", httpMethod = "POST", notes = "新增,更新${table.comment!}数据")
public CommonResult<String> save(@ApiParam(name="${entity}",value="${table.comment!}对象", required = true)@RequestBody ${entity} ${entity?uncap_first}) throws Exception{
String msg = StringUtil.isEmpty(${entity?uncap_first}.getId()) ? "添加${table.comment!}成功" : "更新${table.comment!}成功";
baseService.createOrUpdate(${entity?uncap_first});
return CommonResult.<String>ok().message(msg);
}
</#if>
}
</#if>