controller.ftl 3.88 KB
Newer Older
shenggui.li committed
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
package ${modulePackage}.web.controller.${moduleName};

import ${modulePackage}.${moduleName}.domain.${modelNameUpperCamel};
import ${modulePackage}.${moduleName}.service.${modelNameUpperCamel}Service;
import ${basePackage}.common.restResult.RestResult;
import ${basePackage}.common.restResult.ResultGenerator;
import ${basePackage}.web.aop.Log;
import ${basePackage}.common.restResult.PageParam;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
*
* @author ${author}
* @Description: // TODO 1. 为类添加注释
* @date ${date}
*/
@Slf4j
@RestController
@RequestMapping("${baseRequestMapping}")//TODO 2. 适当修改url
@Api(basePath = "${baseRequestMapping}", tags = "XX模块管理") //TODO 3. 修改tags内容
public class ${modelNameUpperCamel}Controller {
    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @Log
    @PostMapping
    @ApiOperation(value = "新增XX", notes = "单个新增", produces = "application/json") // TODO 4. API方法的说明
    public RestResult add(@ApiParam(name = "XX信息", required = true) ${modelNameUpperCamel} ${modelNameLowerCamel}) { // TODO 5. API方法参数的说明
        ${modelNameLowerCamel}.setCreateTime(new Date());
        ${modelNameLowerCamel}Service.save(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult().setMessage("保存成功");
    }

    @Log
    @DeleteMapping
    @ApiOperation(value = "删除XX", notes = "单个删除", produces = "application/json")
    public RestResult delete(@ApiParam(name = "XX信息", required = true) Long id) {
        ${modelNameLowerCamel}Service.deleteById(id);
        return ResultGenerator.genSuccessResult().setMessage("删除成功");
    }

    @Log
    @PutMapping
    @ApiOperation(value = "修改XX", notes = "单个修改" , code = 200, produces = "application/json")
    public RestResult update(@ApiParam(name = "XX信息", required = true) ${modelNameUpperCamel} ${modelNameLowerCamel}) {
        ${modelNameLowerCamel}.setModifyTime(new Date());
        ${modelNameLowerCamel}Service.update(${modelNameLowerCamel});
        return ResultGenerator.genSuccessResult().setMessage("修改成功");
    }

    @Log
    @GetMapping
    @ApiOperation(value = "获取XX信息", notes = "单个获取", code = 200, produces = "application/json")
    public RestResult detail(@ApiParam(value = "主键ID") @RequestParam Long id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return ResultGenerator.genSuccessResult(${modelNameLowerCamel});
    }

    /**
     * 用于分页查询,默认可以不用传分页信息
     * 默认值:page=1,size=10,sortField="id",sortOrder="ASC"
     */
    @Log
    @GetMapping(value = "/list")
    @ApiOperation(value = "XX列表分页查询", notes = "分页列表", code = 200, produces = "application/json")
    public RestResult list(@ApiParam(value = "分页信息") PageParam pageParam,
                           @ApiParam(value = "查询条件") @RequestParam(required = false, defaultValue = "") String query) {
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.list(pageParam, query);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    /**
     * 下拉框查询所有
     */
    @Log
    @ApiOperation(value = "XX列表查询所有", notes = "下拉框列表", code = 200, produces = "application/json")
    @GetMapping(value = "/all")
    public RestResult listAll() {
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        return ResultGenerator.genSuccessResult(list);
    }

}