service类都测试了都没问题,但是加上以下controller后测试httpclient得到的结果就不正确
来源:2-8 加载图书短评数据
慕仰4837686
2022-12-05 21:52:33
package com.ibaby.ssm.reader.controller; import com.ibaby.ssm.reader.mapper.EvaluationMapper; import com.ibaby.ssm.reader.service.EvaluationService; import com.ibaby.ssm.reader.utils.ResponseUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api/evaluation") public class EvaluationController { @Resource private EvaluationService evaluationService; @GetMapping("/list") public ResponseUtils list(Long bookId){ ResponseUtils responseUtils=null; try { List<Map> list=evaluationService.selectByBookId(bookId); responseUtils=new ResponseUtils().put("list", list); }catch (Exception e){ e.printStackTrace(); responseUtils=new ResponseUtils(e.getClass().getSimpleName(), e.getMessage()); } return responseUtils; } } GET http://localhost:30052/api/evaluation/list?bookId=1 测试结果 HTTP/1.1 500 Content-Type: application/json Content-Length: 170 Date: Mon, 05 Dec 2022 13:53:36 GMT Connection: close { "code": "0", "message": "success", "data": { "list": [ { "evaluation_id": 1, "content": "活动买的很划算,作为开发的工具书真的是很好", "score": 5, "create_time" } ] } } Response code: 500; Time: 1983ms; Content length: 128 bytes
2回答
stonesun1314
2022-12-27
mysql依赖库用最新版本8.0.31会出现数据异常,我改成8.0.16返回数据就正常了
好帮手慕小脸
2022-12-06
同学你好,建议同学按照如下几个思路进行排查尝试:
1、先查看确认数据库中book_id为11的数据有多少条呢?如果只是一条,那么查看显示只有一条数据是正常的
2、查询数据如果是多条的情况下,同学可以对比课程代码检查自己的sql语句是否正确
3、如果上述俩点都可以的话,猜测可能是因同学Mybatis版本较高,出现类型转换异常,从而导致无法获取到数据。则建议同学参考2-9小节(https://class.imooc.com/lesson/2274#mid=56847)进行解决试一下。
4、有可能是缓存导致的,建议同学删除out、target目录,然后重构项目试一下。
祝学习愉快~
相似问题