| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package ${package.Controller};
- import com.taotikee.common.api.CommonResult;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import ${package.Service}.${table.serviceName};
- import ${package.Entity}.${entity};
- import java.io.Serializable;
- import java.util.List;
- <% if(restControllerStyle){ %>
- import org.springframework.web.bind.annotation.RestController;
- <% }else{ %>
- import org.springframework.stereotype.Controller;
- <% } %>
- <% if(isNotEmpty(superControllerClassPackage)){ %>
- import ${superControllerClassPackage};
- <% } %>
- /**
- * <p>
- * ${table.comment!} 前端控制器
- * </p>
- *
- * @author ${author}
- * @since ${date}
- */
- @Api(tags = "${table.controllerName}", description = "${table.controllerName}")
- @Slf4j
- <% if(restControllerStyle){ %>
- @RestController
- <% }else{ %>
- @Controller
- <% } %>
- @RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>")
- <% if(kotlin){ %>
- class ${table.controllerName}<% if(isNotEmpty(superControllerClass)){ %> : ${superControllerClass}()<% } %>
- <% }else{ %>
- <% if(isNotEmpty(superControllerClass)){ %>
- public class ${table.controllerName} extends ${superControllerClass} {
- <% }else{ %>
- public class ${table.controllerName}{
- @Autowired
- public ${table.serviceName} i${entity}Service;
- /**
- * 分页查询所有数据
- *
- * @param pageNo 页码
- * @param pageSize 条数
- * @param ${table.entityPath} 查询实体
- * @return 所有数据
- */
- @ApiOperation("分页查询所有数据")
- @GetMapping
- public CommonResult selectAll(Integer pageNo, Integer pageSize,${entity} ${table.entityPath}) {
- IPage<${entity}> page = new Page<>(pageNo,pageSize);
- return CommonResult.success(this.i${entity}Service.page(page, new QueryWrapper<>(${table.entityPath})));
- }
- /**
- * 通过主键查询单条数据
- *
- * @param id 主键
- * @return 单条数据
- */
- @ApiOperation("通过主键查询单条数据")
- @GetMapping("{id}")
- public CommonResult selectOne(@PathVariable Serializable id) {
- return CommonResult.success(this.i${entity}Service.getById(id));
- }
- /**
- * 新增数据
- *
- * @param ${table.entityPath} 实体对象
- * @return 新增结果
- */
- @ApiOperation("新增数据")
- @PostMapping
- public CommonResult insert(@RequestBody ${entity} ${table.entityPath}) {
- try{
- return CommonResult.success(this.i${entity}Service.save( ${table.entityPath}),"添加成功");
- } catch (Exception e) {
- log.error("出现错误, {}",e.getMessage());
- return CommonResult.failed("添加失败");
- }
- }
- /**
- * 修改数据
- *
- * @param ${table.entityPath} 实体对象
- * @return 修改结果
- */
- @ApiOperation("修改数据")
- @PutMapping
- public CommonResult update(@RequestBody ${entity} ${table.entityPath}) {
- try {
- return CommonResult.success(this.i${entity}Service.updateById(${table.entityPath}),"修改成功");
- } catch (Exception e) {
- log.error("出现错误, {}",e.getMessage());
- return CommonResult.failed("修改失败");
- }
- }
- /**
- * 删除数据
- *
- * @param idList 主键结合
- * @return 删除结果
- */
- @ApiOperation("删除数据")
- @DeleteMapping
- public CommonResult delete(@RequestParam("idList") List<Long> idList) {
- try{
- return CommonResult.success(this.i${entity}Service.removeByIds(idList),"删除成功");
- } catch ( Exception e) {
- log.error("出现错误, {}",e.getMessage());
- return CommonResult.failed("删除失败");
- }
- }
- <% } %>
- }
- <% } %>
|