简体   繁体   English

如何从控制器传递json字符串以查看

[英]how to pass the json string from controller to view

Hi I'm using Spring mvc project in that I have to pass the json String from controller to view the return code from controller is : 嗨,我正在使用Spring mvc项目,因为我必须从控制器传递json字符串以查看从控制器返回的代码是:

return model.addObject("response", Response.getResults().toJSONString()); 返回model.addObject(“ response”,Response.getResults()。toJSONString());

and the jsp code is : 而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>`

I have run the call on postman and it successfully run and but cannot displayed the response string it only shows the jsp coding on postman. 我已经在邮递员上运行了调用,它成功运行了,但是无法显示响应字符串,它仅在邮递员上显示了jsp编码。

can any one help me to fix it? 谁能帮我解决这个问题?

While using Spring Rest Services @RestController plays an important Role. 在使用Spring Rest Services时,@ RestController扮演着重要角色。

@RestController
@RequestMapping("/yourmapping")
public class yourController {

@RequestMapping(method = RequestMethod.GET)
  public <returnType> getAll() {
    return <response>;
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM