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}; <% } %> /** *

* ${table.comment!} 前端控制器 *

* * @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 idList) { try{ return CommonResult.success(this.i${entity}Service.removeByIds(idList),"删除成功"); } catch ( Exception e) { log.error("出现错误, {}",e.getMessage()); return CommonResult.failed("删除失败"); } } <% } %> } <% } %>