package ${package.Controller}; import org.springframework.web.bind.annotation.RequestMapping; #if(${restControllerStyle}) import org.springframework.web.bind.annotation.RestController; #else import org.springframework.stereotype.Controller; #end #if(${superControllerClassPackage}) import ${superControllerClassPackage}; #end import org.springframework.web.bind.annotation.*; import com.kairuidata.thework.model.ResponseMessage; import ${package.Entity}.${entity}; import ${package.Service}.${table.serviceName}; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import org.springframework.beans.factory.annotation.Autowired; import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.kairuidata.thework.utils.JwtTokenUtils; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * <p> * $!{table.comment} 前端控制器 * </p> * * @author Lin * @since ${date} */ @Api(tags = "${table.comment}接口") #if(${restControllerStyle}) @RestController #else @Controller #end @RequestMapping("/api/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") #if(${kotlin}) class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end #else #if(${superControllerClass}) public class ${table.controllerName} extends ${superControllerClass} { #else public class ${table.controllerName} { #end @Autowired private ${table.serviceName} ${table.entityPath}Service; @Autowired private HttpServletRequest request; @ApiOperation("添加") @PostMapping("/add${entity}") public ResponseMessage<${entity}> add${entity}(@RequestBody ${entity} ${table.entityPath}){ ${table.entityPath}.setUserId(JwtTokenUtils.getUserId(request)); if(${table.entityPath}Service.save(${table.entityPath})){ return ResponseMessage.success("添加成功"); } return ResponseMessage.success("添加失败"); } @ApiOperation("根据id删除") @PostMapping("/deleteById") @ApiImplicitParams({ @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true) }) public ResponseMessage<${entity}> deleteById(@RequestBody JSONObject jsonParam){ Integer ${table.entityPath}Id = jsonParam.getInt("${table.entityPath}Id"); if(${table.entityPath}Service.removeById(${table.entityPath}Id)){ return ResponseMessage.success("删除成功"); } return ResponseMessage.success("删除失败"); } @ApiOperation("根据id查询") @PostMapping("/selectById") @ApiImplicitParams({ @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true) }) public ResponseMessage<${entity}> selectById(@RequestBody JSONObject jsonParam){ Integer ${table.entityPath}Id = jsonParam.getInt("${table.entityPath}Id"); ${entity} ${table.entityPath}=${table.entityPath}Service.getById(${table.entityPath}Id); return ResponseMessage.success(${table.entityPath}); } @ApiOperation("根据id更新") @PostMapping("/updateById") @ApiImplicitParams({ @ApiImplicitParam(name = "${table.entityPath}Id", value = "id", dataTypeClass = Integer.class,required = true) }) public ResponseMessage<${entity}> updateById(@RequestBody ${entity} ${table.entityPath}){ if(${table.entityPath}Service.updateById(${table.entityPath})){ return ResponseMessage.success("修改成功"); } return ResponseMessage.success("修改失败"); } @ApiOperation("查询集合") @PostMapping("/selectList") public ResponseMessage<List<${entity}>> selectList() { List<${entity}> ${table.entityPath} = ${table.entityPath}Service.list(new QueryWrapper<${entity}>() .lambda() .eq(${entity}::, ) .orderByDesc(${entity}::getCreateDate)); return ResponseMessage.success(${table.entityPath}); } @ApiOperation("分页查询") @PostMapping("/selectPage") @ApiImplicitParams({ @ApiImplicitParam(name = "current", value = "当前页", dataTypeClass = Integer.class, required = true) }) public ResponseMessage<PageEntity> selectMyTicket(@RequestBody JSONObject jsonParam) { Integer current = jsonParam.getInt("current", 1); int userId = JwtTokenUtils.getUserId(request); Page<${entity}> ${table.entityPath}Page = new Page<>(current, 15); Page<${entity}> type2 = ${table.entityPath}Service.page(${table.entityPath}Page, new QueryWrapper<${entity}>() .lambda() .eq(${entity}::getUserId, userId) .orderByDesc(${entity}::getCreateDate)); List<${entity}> records = type2.getRecords(); PageEntity pageEntity = new PageEntity(type2.getCurrent(), type2.getSize(), type2.getTotal(), records); return ResponseMessage.success(pageEntity); } } #end
MybatisPuls-VM模板
于 2022-06-22 14:51:02 首次发布