springmvc responsebody return对象中的数据,和前台json展示的数据不一样

发生的问题
在写controller 接口的时候,在返回@ResponseBody对象的时候,对象的数据和前端的json对象不一样。

以下帖一下代码:

    @RequestMapping("cxcy/getCXCYIndexModel")
    @ResponseBody
    public CommonIndexResponse getCXCYIndexModel(NoLoginRequest request)
    {

        CommonIndexResponse response = new CommonIndexResponse();
//        try {
            ListResponse resp = carouselService.getCarouselByTopCategoryID(TopCategoryConstant.CXCY_ID, CarouselConstant.WEB_INDEX_TOP_CATEGORY_CAROUSEL);

            response.setBanner(resp.getCommonList());


            List<TitleAndListResult> titleAndListResults = new ArrayList<TitleAndListResult>();

            TitleAndListResult titleAndListResult1 = new TitleAndListResult();

            titleAndListResult1.setTitleName("最新创业项目");

            List<ProjectInfo> projectInfos1 = projectInfoService.getProjectInfoByQueryCondition(null, 0, 4, 0, SortRuleConstant.LATEST, 0);

            titleAndListResult1.setCommonList(projectInfos1);

            TitleAndListResult titleAndListResult2 = new TitleAndListResult();

            titleAndListResult2.setTitleName("人气创业项目");

            List<ProjectInfo> projectInfos2 =projectInfoService.getProjectInfoByQueryCondition(null, 0, 4, 0, SortRuleConstant.TRADE, 0);

            titleAndListResult2.setCommonList(projectInfos2);

            TitleAndListResult titleAndListResult3 = new TitleAndListResult();

            titleAndListResult3.setTitleName("土豪创新项目");

            List<ProjectInfo> projectInfos3 =projectInfoService.getProjectInfoByQueryCondition(null, 0, 4, 0, SortRuleConstant.MONEY_CXCY, 0);

            titleAndListResult2.setCommonList(projectInfos3);

            titleAndListResults.add(titleAndListResult1);

            titleAndListResults.add(titleAndListResult2);

            titleAndListResults.add(titleAndListResult3);

            response.setTitleAndListResults(titleAndListResults);

            response.setSecondCategoryList(secondCategoryService.getSecondCategoryByTopCategoryID(TopCategoryConstant.CXCY_ID).getCommonList());

            response.setStatusCode(Response.SUCCESS);

        System.out.println();
//        }
//        catch (Exception e)
//        {
//            response.setStatusCode(Response.FAILED);
//            response.setMsg("服务器内部UC哦呜");
//        }

        return  response;

    }

我在debug 显示的时候,得到的数据是

clipboard.png

commonList 也是有值的

clipboard.png

但是请求之后前端获取的JSON这一块的值就只有{},{},{}
clipboard.png

有没有大神能告诉我哪里有问题?

研究了一下,发现是lombok的getter/setter注解,与springmvc 的ResponseBody注解产生的问题。

阅读 4.6k
1 个回答

我检查到,应该是与lombok 使用的注解有关系,但是具体是什么原因还未查出

经过测试得出以下结论:1、如果用junit对api接口进行测试打印出的数据内容是正确的。在浏览器请求出的json数据是有误的。2、如果不用lombok来注解实体类,那么就不会发生以上错误。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题