Controller.java.vm 2.2 KB
Newer Older
zlt2000's avatar
zlt2000 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
package ${package}.${moduleName}.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import ${package}.${moduleName}.model.${className};
zlt2000's avatar
zlt2000 已提交
14
import ${package}.${moduleName}.service.I${className}Service;
zlt2000's avatar
zlt2000 已提交
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
import com.central.common.model.PageResult;
import com.central.common.model.Result;

/**
 * ${comments}
 *
 * @author ${author}
 * @date ${datetime}
 */
@Slf4j
@RestController
@RequestMapping("/${pathName}")
@Api(tags = "${comments}")
public class ${className}Controller {
    @Autowired
    private I${className}Service ${classname}Service;

    /**
     * 列表
     */
    @ApiOperation(value = "查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
    })
zlt2000's avatar
zlt2000 已提交
40
    @GetMapping
zlt2000's avatar
zlt2000 已提交
41 42 43 44 45 46 47 48
    public PageResult list(@RequestParam Map<String, Object> params) {
        return ${classname}Service.findList(params);
    }

    /**
     * 查询
     */
    @ApiOperation(value = "查询")
zlt2000's avatar
zlt2000 已提交
49
    @GetMapping("/{${pk.attrname}}")
zlt2000's avatar
zlt2000 已提交
50
    public Result findUserById(@PathVariable Long ${pk.attrname}) {
zlt2000's avatar
zlt2000 已提交
51
        ${className} model = ${classname}Service.getById(${pk.attrname});
zlt2000's avatar
zlt2000 已提交
52 53 54 55 56 57 58
        return Result.succeed(model, "查询成功");
    }

    /**
     * 新增or更新
     */
    @ApiOperation(value = "保存")
zlt2000's avatar
zlt2000 已提交
59
    @PostMapping
zlt2000's avatar
zlt2000 已提交
60
    public Result save(@RequestBody ${className} ${classname}) {
zlt2000's avatar
zlt2000 已提交
61
        ${classname}Service.saveOrUpdate(${classname});
zlt2000's avatar
zlt2000 已提交
62 63 64 65 66 67 68
        return Result.succeed("保存成功");
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
zlt2000's avatar
zlt2000 已提交
69
    @DeleteMapping("/{id}")
zlt2000's avatar
zlt2000 已提交
70 71 72 73 74
    public Result delete(@PathVariable Long ${pk.attrname}) {
        ${classname}Service.removeById(${pk.attrname});
        return Result.succeed("删除成功");
    }
}