Jackson JsonView
2016-02-27 00:00
706 查看
摘要: Jackson JsonView
在Spring MVC -> ResponseEntity,有One2Many等映射,一般会标注@JsonIgnore,在返回时忽略级联关系,但是有些场景会要求返回级联对象,所以@JsonIgnore是不满足需求的,所以引入了@JsonView,在控制层动态的指定返回字段。
0Controller中:
参考:http://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/htmlsingle/#mvc-ann-jsonview
在Spring MVC -> ResponseEntity,有One2Many等映射,一般会标注@JsonIgnore,在返回时忽略级联关系,但是有些场景会要求返回级联对象,所以@JsonIgnore是不满足需求的,所以引入了@JsonView,在控制层动态的指定返回字段。
0Controller中:
@RestController public class UserController { @RequestMapping(value = "/user", method = RequestMethod.GET) @JsonView(User.WithoutPasswordView.class) public User getUser() { return new User("eric", "7!jd#h23"); } }
public class User { public interface WithoutPasswordView {}; public interface WithPasswordView extends WithoutPasswordView {}; private String username; private String password; public User() { } public User(String username, String password) { this.username = username; this.password = password; } @JsonView(WithoutPasswordView.class) public String getUsername() { return this.username; } @JsonView(WithPasswordView.class) public String getPassword() { return this.password; } }
参考:http://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/htmlsingle/#mvc-ann-jsonview
相关文章推荐
- Handler配合数据下载,网上下载并解析JSON的例子(18)
- js keypress 对输入中文不响应
- angular js中文教程笔记
- 用一段JS代码来比较各浏览器的极限内存与运算速度
- JSP—九大隐式对象之out
- JavaScript高级程序设计(第3版)第三章读书笔记
- javascript闭包 -- 懂不懂由你,反正我是懂了
- 【读书笔记】javascript之数组操作
- jsp page指令详解
- 纯JS实现省市县三级联动
- Ajax发送和接收请求
- 对js中Function的浅见
- JS继承方式详解
- 160227、javascript特效
- 160226、js常用的验证
- Gson和Fastjson解析对比
- js原型及原型链
- JavaScript动态加载ul标签
- web小游戏 2048制作(四):过场动画 showanimation2048.js
- web小游戏 2048制作(三):辅助函数 support2048.js