Controller.ftl
3.03 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
package ${package}.rest;
import com.topdraw.aop.log.Log;
import ${package}.domain.${className};
import ${package}.service.${className}Service;
import ${package}.service.dto.${className}QueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @author ${author}
* @date ${date}
*/
@Api(tags = "${className}管理")
@RestController
@RequestMapping("/api/${changeClassName}")
public class ${className}Controller {
@Autowired
private ${className}Service ${changeClassName}Service;
@GetMapping(value = "/download")
@Log("导出数据")
@ApiOperation("导出数据")
public void download(HttpServletResponse response, ${className}QueryCriteria criteria) throws IOException {
${changeClassName}Service.download(${changeClassName}Service.queryAll(criteria), response);
}
@GetMapping
@Log("查询${className}")
@ApiOperation("查询${className}")
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable) {
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
}
@GetMapping(value = "/all")
@Log("查询所有${className}")
@ApiOperation("查询所有${className}")
public ResponseEntity get${className}s(${className}QueryCriteria criteria) {
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria),HttpStatus.OK);
}
@PostMapping
@Log("新增${className}")
@ApiOperation("新增${className}")
public ResponseEntity create(@Validated @RequestBody ${className} resources) {
return new ResponseEntity<>(${changeClassName}Service.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改${className}")
@ApiOperation("修改${className}")
public ResponseEntity update(@Validated @RequestBody ${className} resources) {
${changeClassName}Service.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@DeleteMapping(value = "/{${pkChangeColName}}")
@Log("删除${className}")
@ApiOperation("删除${className}")
public ResponseEntity delete(@PathVariable ${pkColumnType} ${pkChangeColName}) {
${changeClassName}Service.delete(${pkChangeColName});
return new ResponseEntity<>(HttpStatus.OK);
}
<#if columns??>
<#list columns as column>
<#if column.columnName == 'code'>
@GetMapping(value = "/getByCode/{code}")
@Log("根据标识查询")
@ApiOperation(value = "根据标识查询")
public ResponseEntity getByCode(@PathVariable String code) {
return new ResponseEntity(${changeClassName}Service.getByCode(code),HttpStatus.OK);
}
</#if>
</#list>
</#if>
}