后台数据查询接口的书写出错
报错内容:
[ 系统异常 ]nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
查询语句查出多条数据,但是返回的类型只能是一条
解决方案(改后代码):
/**ReportServiceImpl.java*/ @Override public List<Report> findReportById(Integer id) { List<Report> report = reportMapper.findReportById(id); return report; }
/**ReportController.java*/ @GetMapping("find_report_by_id") public JsonData findReportById(Integer id){ List<Report> report = reportService.findReportById(id); return JsonData.buildSuccess(report); }
/**ReportMapper.java*/ List<Report> findReportById(@Param("id") Integer id);
/**ReportService*/ List<Report> findReportById(@Param("id") Integer id);