springboot2.0过滤不需要返回的字段

    技术2025-09-23  6

    springboot2.0过滤不需要返回的字段

    过滤值为空的字段 在yml文件中添加: spring: jackson: default-property-inclusion: non_null 2、过滤不需要返回的字段但是字段值不为空 在实体类上方添加注解 @JsonIgnoreProperties(values={“字段名称”}) 比如:创建时间和修改时间不反回 @JsonIgnoreProperties(values{"createTime","updateTime"}) pubic class Student{ private Long id; private String name; private String sex; private Date createTime; privae Date updateTime; }

    在网上查找的还有另外一种方法,就是在字段上方添加@JsonIgnore注解,但是我加了后还是返回,不知道为什么

    Processed: 0.014, SQL: 9