@GetMapping("/comment/toCommentIds") public ApiResult<List<Object>> findToCommentIds() throws BusinessCodeException { List<Object> toCommentIds = commentService.findToCommentIds(); //不存在任何toCommentId,comment表为空 if(toCommentIds.size() == 0) { throw new BusinessCodeException(BusinessCode.COMMENT_QUERY_EXCEPTION.getMsg(), BusinessCode.COMMENT_QUERY_EXCEPTION.getCode()); } return ApiResultHandler.successResult(toCommentIds); }
时间: 2024-02-26 07:52:27 浏览: 135
这段代码是用来实现获取评论中的 toCommentId 列表的,使用了 Spring MVC 的注解 @GetMapping 和返回值封装工具类 ApiResult。在方法内部,通过 commentService.findToCommentIds() 方法获取到 toCommentId 列表,如果列表为空,则会抛出自定义异常 BusinessCodeException,异常中包含错误信息和错误码。如果列表不为空,则将列表封装到 ApiResult 中返回。
相关问题
@GetMapping("/comments/{page}/{size}") public ApiResult<IPage<CommentVO>> findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size) { Page<CommentVO> commentVOPage = new Page<>(page, size); IPage<CommentVO> all = commentService.findAll(commentVOPage); return ApiResultHandler.successResult(all); }
这段代码看起来是一个 Spring Boot 的控制器,它定义了一个 GET 请求的路由 "/comments/{page}/{size}",其中 page 和 size 是路径参数,用于分页查询评论。控制器中通过调用 CommentService 的 findAll 方法来获取评论数据,并将其封装在一个 ApiResult 对象中返回给客户端。其中,ApiResultHandler 是一个用于处理 ApiResult 的工具类,它将数据转换成 JSON 格式的字符串并设置 HTTP 响应头信息。
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package com.liruilong.hros.controller.statistics; import com.liruilong.hros.model.datas.DataModel; import com.liruilong.hros.service.EmployeeService; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping({"/statistics/personnel"}) public class PersonnelController { @Autowired EmployeeService employeeService; public PersonnelController() { } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/Position"}) public List<DataModel> DataViewPosition() { return this.employeeService.dataViewPosition(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/JobLevel"}) public List<DataModel> DataViewJobLevel() { return this.employeeService.dataViewJobLevel(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/Department"}) public List<DataModel> DataViewDepartment() { return this.employeeService.dataViewDepartment(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/tiptopdegree"}) public List<DataModel> DataViewtiptopdegree() { return this.employeeService.dataViewtiptopdegree(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/school"}) public List<DataModel> DataViewschool() { return this.employeeService.dataViewschool(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/nation"}) public List<DataModel> DataViewNation() { return this.employeeService.dataViewNation(); } @Scheduled( cron = "0 0 3 * * ?" ) @GetMapping({"/politicsstatus"}) public List<DataModel> DataViewPoliticsstatus() { return this.employeeService.dataViewPoliticsstatus(); } }
这是一段Java代码,是一个名为PersonnelController的类,它位于com.liruilong.hros.controller.statistics包中。该类有七个公共方法,分别为DataViewPosition、DataViewJobLevel、DataViewDepartment、DataViewtiptopdegree、DataViewschool、DataViewNation和DataViewPoliticsstatus。这些方法都使用了@GetMapping注释,它们将在指定时间(cron表达式中指定)调用,并返回一个List<DataModel>对象。该类还使用了@Autowired注释,以注入一个名为employeeService的EmployeeService对象。另外,该类还使用了@Scheduled注释,以指定每个方法的调用时间。
阅读全文
相关推荐
















