Java 在SpringBoot Rest控制器中与Jackson@JsonIgnore协作MongoDB延迟加载
我已经在我的Java 在SpringBoot Rest控制器中与Jackson@JsonIgnore协作MongoDB延迟加载,java,mongodb,orm,jackson,lazy-loading,Java,Mongodb,Orm,Jackson,Lazy Loading,我已经在我的SpringBoot应用程序中编写了一个RestController。我也在使用MongoDB。这是我的实体: public class LocationEntity { @Id private String id; private String name; @DBRef(lazy = true) @JsonIgnore private UserEntity owner; private String descripti
SpringBoot
应用程序中编写了一个RestController
。我也在使用MongoDB
。这是我的实体:
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;
}
}
公共类位置实体{
@身份证
私有字符串id;
私有字符串名称;
@DBRef(lazy=true)
@杰索尼奥雷
私人用户实体所有者;
私有字符串描述;
@DBRef(lazy=true)
私有列表角色;
私人日期;
public LocationEntity(字符串名称、UserEntity所有者、字符串描述、列表角色、日期){
this.name=名称;
this.owner=所有者;
this.description=描述;
this.roles=角色;
this.date=日期;
}
}
RoleEntity
和UserEntity
也是来自同一数据库的实体。
MyRestController
的方法返回ResponseEntity
,因此默认情况下,内部使用Jackson
将对象
序列化为JSON
。
我想问一下关于延迟加载的问题。如果我使用Jackson
中的@JsonIgnore
忽略序列化中的该字段,ORM不会从数据库中获取“惰性字段”吗
提前谢谢你的帮助 ORM将仅在需要时获取那些延迟加载的字段。这意味着,如果您指示Jackson在序列化过程中忽略它们(使用
@JsonIgnore
注释),ORM将不会获取它们