博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springmvc手动渲染jsp
阅读量:4589 次
发布时间:2019-06-09

本文共 966 字,大约阅读时间需要 3 分钟。

因为需要MockHttpServletResponse对象来得到输出的内容,要引入的包

org.springframework
spring-test
5.1.6.RELEASE

注入ViewResolver解析页面

@Autowired    private InternalResourceViewResolver viewResolver;

使用过程

@GetMapping("test")    public JsonResult test(HttpServletRequest request,                           HttpServletResponse response)throws Exception{        ModelMap map = new ModelMap();        map.put("param_json", "asdasd");        map.put("loginuser", null);        View resolve = viewResolver.resolveViewName("design", Locale.CHINA);        MockHttpServletResponse mockResp = new MockHttpServletResponse();        resolve.render(map, request, mockResp);        System.out.println("rendered html : " + mockResp.getContentAsString());        return JsonResult.ok(mockResp.getContentAsString(), null);    }

查看打印和返回的结果,发现生成了html

 

 

转载于:https://www.cnblogs.com/grasp/p/11052717.html

你可能感兴趣的文章
vim 撤销 恢复 快捷键
查看>>
python导入import requests报错
查看>>
Hexo博客搭建
查看>>
内部类详解(很详细)
查看>>
dubbox系列【三】——简单的dubbox提供者+消费者示例
查看>>
常见sql 写法总结
查看>>
Windows xp搭建Windows Phone 7开发环境
查看>>
[bzoj] 1597 土地购买 || 斜率优化dp
查看>>
Lodop的JS模版代码、文档式模版 生成加载赋值博文索引
查看>>
Python安装和开发环境搭建
查看>>
[USACO4.2] 草地排水 Drainage Ditches (最大流)
查看>>
dotnetcore+vue+elementUI 前后端分离 三(前端篇)
查看>>
gdb输入输出重定向
查看>>
包含.h就可以用其对应的函数
查看>>
mysql忘记root密码的处理方法
查看>>
Newtonsoft.Json之JArray, JObject, JProperty,JValue
查看>>
OO Summary (Homework 9-11)
查看>>
fedora 解决yumBackend.py进程CPU占用过高
查看>>
NTP 协议介绍
查看>>
软件测试 · 白盒测试
查看>>