8人参与 • 2025-06-10 • Javascript
但是没有给@data 导致没有get/set方法,请求一直报错
public class jsonresult<t> { private int code; private string message; private t data; public jsonresult() {} public jsonresult(int code, string message, t data) { this.code = code; this.message = message; this.data = data; } public int getcode() { return code; } public void setcode(int code) { this.code = code; } public string getmessage() { return message; } public void setmessage(string message) { this.message = message; } public t getdata() { return data; } public void setdata(t data) { this.data = data; } public static <t> jsonresult<t> success(t data) { return new jsonresult<>(200, "success", data); } }
spring mvc 在序列化时无法将对象正确转换为 json,因此会被视为 视图名称,导致循环视图渲染的问题。
completed initialization in 2 ms get "/api/getuser", parameters={} mapped to kayou.eim.controller.basiccontroller#users() using 'application/octet-stream', given [*/*] and supported [*/*] using @exceptionhandler kayou.eim.controller.global.globalexceptionhandler#handleexception(except internal server error org.springframework.web.httpmediatypenotacceptableexception: could not find acceptable representation resolved [org.springframework.web.httpmediatypenotacceptableexception: could not find acceptable representation] completed 406 not_acceptable "error" dispatch for get "/api/error", parameters={} mapped to kayou.eim.controller.global.customerrorcontroller#error(httpservletrequest) using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, appli writing [{timestamp=wed may 07 18:09:17 cst 2025, status=406, error=not acceptable, path=/api/getuser}] exiting from "error" dispatch, status 406
{ "timestamp": 1746612557176, "status": 406, "error": "not acceptable", "path": "/api/getuser" }
报错不够清晰准确,导致排查了一圈。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论