controller.vm
1.93 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
package ${packageName};
import ${table.EntityFullClassName};
import ${table.ServiceFullClassName};
import ${table.basePackageName}.bean.core.BussinessLog;
import ${table.basePackageName}.bean.constant.factory.PageFactory;
import ${table.basePackageName}.bean.enumeration.BizExceptionEnum;
import ${table.basePackageName}.bean.exception.ApplicationException;
import ${table.basePackageName}.bean.vo.front.Rets;
import ${table.basePackageName}.utils.StringUtil;
import ${table.basePackageName}.utils.factory.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("${table.UriPrefix}")
public class ${table.ControllerClassName} {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private ${table.ServiceClassName} ${table.ServiceInstanceName};
@RequestMapping(value = "/list",method = RequestMethod.GET)
public Object list() {
Page<${table.EntityClassName}> page = new PageFactory<${table.EntityClassName}>().defaultPage();
page = ${table.ServiceInstanceName}.queryPage(page);
return Rets.success(page);
}
@RequestMapping(method = RequestMethod.POST)
@BussinessLog(value = "编辑${table.Label}", key = "name")
public Object save(@ModelAttribute ${table.EntityClassName} ${table.entityNameLowerFirstChar}){
if(${table.entityNameLowerFirstChar}.getId()==null){
${table.ServiceInstanceName}.insert(${table.entityNameLowerFirstChar});
}else {
${table.ServiceInstanceName}.update(${table.entityNameLowerFirstChar});
}
return Rets.success();
}
@RequestMapping(method = RequestMethod.DELETE)
@BussinessLog(value = "删除${table.Label}", key = "id")
public Object remove(Long id){
if (StringUtil.isEmpty(id)) {
throw new ApplicationException(ApplicationExceptionEnum.REQUEST_NULL);
}
${table.ServiceInstanceName}.deleteById(id);
return Rets.success();
}
}