ObjectMapper 中的两个方法 中writeValue和writeValueAsString的区别


https://blog.csdn.net/qq_43061290/article/details/104577391

```
//把保存数据序列化为json数据
ObjectMapper mapper=new ObjectMapper();
String josn = mapper.writeValueAsString(info);
//设置content-Type
response.setContentType("application/json;charset=utf-8");
//把json写到前台页面
response.getWriter().write(josn);
```
直接写给前端不做任何处理

```
ObjectMapper mapper = new ObjectMapper();

response.setContentType("application/json;charset=utf-8");
mapper.writeValue(response.getOutputStream(),info);

```
写给前端之前先把数据封装到session中,一般用于登陆后在前端显示用户名


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM