在网上查找到原因如下:
代码中使用的是Get请求,但是使用了@RequestBody进行数据的封装,因为Get请求发送数据的方式不是json格式,所以当我们使用@RequsetBody封装Get请求的数据时就会出现无法获取到数据的情况;
@GetMapping("selectNoticeByUserIdAndNoticeType")
public R selectNoticeByUserIdAndNoticeType(@RequestBody Notice notice){
List<Object> notices = noticeRepository.selectNoticeByNoticeReceiveUserIdAndNoticeType(notice.getNoticeReceiveUserId(),notice.getNoticeType());
return R.ok().data("noticesDesc",notices);
}
自定义查询语句
@Query(" select n,u from Notice n,user u WHERE n.noticeSendUserId=u.userId and n.noticeReceiveUserId=?1 and n.noticeType=?2 " +
"ORDER BY n.noticeTime desc")
List<Object> selectNoticeByNoticeReceiveUserIdAndNoticeType(Integer userId,Integer type);
解决
将请求改为put就OK

本文探讨了在使用GET请求时结合@RequestBody注解导致的数据无法获取问题,并提供了解决方案,即将请求方式更改为PUT。
715

被折叠的 条评论
为什么被折叠?



