@JsonView注解的使用
看到一个新的注解以前没有用过,记录一下使用方法。 注意是:com.fasterxml.jackson.annotation.JsonView @JsonView可以过滤pojo的属性,使Controller在返回json时候,pojo某些属性不返回,比如User的密码,一般是不返回的,就可以使用这个注解。 @JsonView使用方法: 1,使用 接口 来声明多个视图 2,在pojo的get方法上指定视图 3,在Controller方法上指定视图 例子:条件查询时候不返回用户的密码,查看详情时候返回用户的密码 User: package com.imooc.dto; import com.fasterxml.jackson.annotation.JsonView; public class User { public interface UserSimpleView {}; public interface UserDetailView extends UserSimpleView{}; // 继承 private String username; private String password; // UserSimpleView视图有 @JsonView(UserSimpleView. class ) public String getUsername() {