Java json数据和spring视图名称如何一起返回
我在spring中退出了新的带有json结构的mvc。一点点咖啡 在我的程序中,我的控制器中有以下请求处理程序Java json数据和spring视图名称如何一起返回,java,json,Java,Json,我在spring中退出了新的带有json结构的mvc。一点点咖啡 在我的程序中,我的控制器中有以下请求处理程序 @ResponseBody @RequestMapping(value = "/jsonTable", method = RequestMethod.GET) public String populateJsonTable(@ModelAttribute("model") Person model) { DataTables<Person> dt = new Dat
@ResponseBody
@RequestMapping(value = "/jsonTable", method = RequestMethod.GET)
public String populateJsonTable(@ModelAttribute("model") Person model) {
DataTables<Person> dt = new DataTables<Person>();
Person person = new Person();
List<Person> personList = person.findMatches(ctxt.getSession(), 1);
dt.setEntityData(personList);
dt.setiTotalDisplayRecords(5);
return JsonUtil.toJson(dt);
}
对不起,弄错了。我第一次使用statck
代码更改后,我得到了以下错误
(更改代码)
@ResponseBody
@RequestMapping(value=“/jsonTable”,method=RequestMethod.GET)
public model和view populateJsonTable(@modeldattribute(“model”)Person model){
DataTables dt=新的DataTables();
映射结果=新的HashMap();
Person=新人();
List personList=person.findMatches(ctxt.getSession(),1);
dt.setEntityData(个人列表);
dt.setiTotalDisplayRecords(5);
result.put(“personList”,JsonUtil.toJson(dt));
返回新的ModelAndView(“TeamViewer”,结果);
}
错误:
此请求标识的资源只能根据请求“accept”头()生成具有不可接受特征的响应
Jsp页面如下所示
<head>
<meta http-equiv="Content-Type" content="application/json; charset=windows-1252">
<title>JSP Page</title>
<c:set var="baseURL" value="${pageContext.request.contextPath}"/>
<link href="${baseURL}/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/css/jtable_green.css" rel="stylesheet" type="text/css" />
<script src="${baseURL}/js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/jquery.jtable.js" type="text/javascript"></script>
<script src="${baseURL}/js/json2.js" type="text/javascript"></script>
</head>
JSP页面
我仍然无法阻止任何人帮助我。将控制器返回类型更改为ModelAndView。我已经更新了你的代码。尝试以下方法
@ResponseBody
@RequestMapping(value = "/jsonTable", method = RequestMethod.GET)
public ModelAndView populateJsonTable(@ModelAttribute("model") Person model) {
DataTables<Person> dt = new DataTables<Person>();
Map<String, Object> result = new HashMap<String, Object>();
Person person = new Person();
List<Person> personList = person.findMatches(ctxt.getSession(), 1);
dt.setEntityData(personList);
dt.setiTotalDisplayRecords(5);
result.put("personList", JsonUtil.toJson(dt));
return new ModelAndView("your jsp page here e.g page/personForm", result);
}
@ResponseBody
@RequestMapping(value=“/jsonTable”,method=RequestMethod.GET)
public model和view populateJsonTable(@modeldattribute(“model”)Person model){
DataTables dt=新的DataTables();
映射结果=新的HashMap();
Person=新人();
List personList=person.findMatches(ctxt.getSession(),1);
dt.setEntityData(个人列表);
dt.setiTotalDisplayRecords(5);
result.put(“personList”,JsonUtil.toJson(dt));
返回新的ModelAndView(“这里是您的jsp页面,例如page/personForm”,result);
}
除非答案不清楚/无法访问,否则不要对答案区域进行任何编辑。无论你想表明什么立场,请更新你的问题,我会更新答案。你好,阿肖克先生。你能多帮点忙吗。
<head>
<meta http-equiv="Content-Type" content="application/json; charset=windows-1252">
<title>JSP Page</title>
<c:set var="baseURL" value="${pageContext.request.contextPath}"/>
<link href="${baseURL}/css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="${baseURL}/css/jtable_green.css" rel="stylesheet" type="text/css" />
<script src="${baseURL}/js/jquery-1.6.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="${baseURL}/js/jquery.jtable.js" type="text/javascript"></script>
<script src="${baseURL}/js/json2.js" type="text/javascript"></script>
</head>
@ResponseBody
@RequestMapping(value = "/jsonTable", method = RequestMethod.GET)
public ModelAndView populateJsonTable(@ModelAttribute("model") Person model) {
DataTables<Person> dt = new DataTables<Person>();
Map<String, Object> result = new HashMap<String, Object>();
Person person = new Person();
List<Person> personList = person.findMatches(ctxt.getSession(), 1);
dt.setEntityData(personList);
dt.setiTotalDisplayRecords(5);
result.put("personList", JsonUtil.toJson(dt));
return new ModelAndView("your jsp page here e.g page/personForm", result);
}