springmvc注解,【Java】使用springboot框架中的注解@ManyToOne遇到的坑

 2023-10-06 阅读 31 评论 0

摘要:包如下的錯:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed 1.在一個對象的屬性中使用@ManyToOne對于某一個關聯的字段時,在使用findAll會報如下的錯,如下圖是在一個對象中使用了@ManyToOne

包如下的錯:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

1.在一個對象的屬性中使用@ManyToOne對于某一個關聯的字段時,在使用findAll會報如下的錯,如下圖是在一個對象中使用了@ManyToOne

但是findAll會報如下的錯,并且查詢時返回很多的字段和數據,但是有些不是你想要的,如下圖所示

springmvc注解,解決方法:

在查詢的時候,不返回@ManyToOne注解的這個字段即可解決這個錯,代碼如下

 @RequestMapping(method = RequestMethod.GET)public Object listAllStreams(@RequestBody JSONObject param) {JSONObject result;try {List<Stream> streams = streamService.listAll(param);JSONArray jsonArray = new JSONArray();for(Stream stream:streams){JSONObject object = new JSONObject();object.fluentPut("name",stream.getName()).fluentPut("fields",stream.getFields()).fluentPut("from", stream.getFrom()).fluentPut("groupBy",stream.getGroupBy()).fluentPut("identifier",stream.getIdentifier()).fluentPut("keyBy",stream.getKeyBy()).fluentPut("solution",stream.getSolution());jsonArray.add(object);}result = onSuccess(streams);} catch (Exception e) {log.error("{query all stream failed, reason : {}}", e);String error = e.getMessage();result = onFail(error);}return result;}

?

最后返回的結果與預期一樣。這是個人的經驗總結,如有更好歡迎討論。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/120706.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息