猿问

SpringBoot Rest Controller中与Jackson @JsonIgnore合作

RestController我在我的应用程序中写了一个SpringBoot。MongoDB我也在用a 。这是我的实体:


public class LocationEntity {


    @Id

    private String id;


    private String name;


    @DBRef(lazy = true)

    @JsonIgnore

    private UserEntity owner;


    private String description;


    @DBRef(lazy = true)

    private List<RoleEntity> roles;


    private Date date;


    public LocationEntity(String name, UserEntity owner, String description, List<RoleEntity> roles, Date date) {

         this.name = name;

         this.owner = owner;

         this.description = description;

         this.roles = roles;

         this.date = date;

    }

}

RoleEntity和UserEntity也是来自同一数据库的实体。我RestController的方法返回ResponseEntity,所以默认情况下Jackson是用内部来序列化Object的JSON。我想问一下延迟加载的具体情况。如果我使用@JsonIgnorefromJackson忽略序列化中的该字段,ORM 不会从数据库获取“惰性字段”吗?


提前感谢您的帮助!


守着一只汪
浏览 114回答 1
1回答

江户川乱折腾

ORM 只会在需要时获取那些延迟加载的字段。这意味着如果您指示 Jackson 在序列化期间忽略它们(使用@JsonIgnore注释),ORM 将不会获取它们。
随时随地看视频慕课网APP

相关分类

Java
我要回答