Java 如何将json字符串从控制器传递到视图
您好,我正在使用Spring mvc项目,因为我必须从controller传递Java 如何将json字符串从控制器传递到视图,java,spring,rest,model-view-controller,Java,Spring,Rest,Model View Controller,您好,我正在使用Spring mvc项目,因为我必须从controller传递json字符串,以查看controller返回的代码是: 返回model.addObject(“response”,response.getResults().toJSONString()) jsp代码是: <%@ page language="java" content Type="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%
json
字符串,以查看controller返回的代码是:
返回model.addObject(“response”,response.getResults().toJSONString())
jsp代码是:
<%@ page language="java" content Type="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
`<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Response value</title>
</head>
<body>
Response is : <c:out value="${response}" />
</body>
</html>`
` 在使用SpringRESTServices时@RestController起着重要的作用
@RestController
@RequestMapping("/yourmapping")
public class yourController {
@RequestMapping(method = RequestMethod.GET)
public <returnType> getAll() {
return <response>;
}
}
@RestController
@请求映射(“/yourmapping”)
公共类控制器{
@RequestMapping(method=RequestMethod.GET)
公共getAll(){
回来
}
}
感谢您的回复我也使用了这个,但工作不正常。然后我检查了jsp的版本,然后添加了标签,它会正常工作。