当前位置 : 主页 > 编程语言 > python >

controller返回json数据,过滤属性

来源:互联网 收集:自由互联 发布时间:2023-03-22
User user = new User();user.setId(1L);user.setAge(12);user.setName("zhangsan");user.setBirthDate(new Date());String jsonString1 = JSON.toJSONString(user);System.out.println(jsonString1);SimplePropertyPreFilter filter = new SimplePropertyPre

User user = new User();user.setId(1L);user.setAge(12);user.setName("zhangsan");user.setBirthDate(new Date());String jsonString1 = JSON.toJSONString(user);System.out.println(jsonString1);SimplePropertyPreFilter filter = new SimplePropertyPreFilter(User.class, "na", "address");String jsonString2 = JSON.toJSONString(user, filter);System.out.println(jsonString2);

输出结果

{"id":1,"na":"zhangsan","address":null,"birthDate":"2018-01-08 14:24:28"}{"na":"zhangsan","address":null}

上面是在代码中体现的过滤数据,下面直接使用注解

1.@JSONField(serialize = false)

2.@JsonIgnore 

 

网友评论