【问题标题】:how to pass the json string from controller to view如何将json字符串从控制器传递到视图
【发布时间】:2015-10-28 05:29:39
【问题描述】:

您好,我正在使用 Spring mvc 项目,因为我必须从控制器传递 json 字符串才能查看控制器的返回代码:

return 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>`

我在邮递员上运行了调用,它成功运行,但无法显示响应字符串,它只显示邮递员上的jsp编码。

谁能帮我解决?

【问题讨论】:

    标签: java spring rest model-view-controller


    【解决方案1】:

    在使用 Spring Rest Services 时,@RestController 起着重要的作用。

    @RestController
    @RequestMapping("/yourmapping")
    public class yourController {
    
    @RequestMapping(method = RequestMethod.GET)
      public <returnType> getAll() {
        return <response>;
      }
    
    }
    

    【讨论】:

    • 感谢您的回复,我也使用了这个但不能正常工作。然后我检查了 jsp 的版本,然后我添加了 标签它会正常工作.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 2017-02-21
    • 2019-11-27
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多