java - SpringBoot Rest Controller中与Jackson@JsonIgnore合作MongoDB延迟加载
问题描述
我RestController
在我的SpringBoot
应用程序中写了一个。我也在使用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;
}
}
RoleEntity
和UserEntity
也是来自同一数据库的实体。我RestController
的方法返回ResponseEntity
,所以默认Jackson
是用里面序列化Object
到的JSON
。我想准确地询问延迟加载。如果我在序列化中使用@JsonIgnore
fromJackson
忽略该字段,ORM 不会从数据库中获取“惰性字段”吗?
提前感谢您的帮助!
解决方案
ORM 只会在需要时获取那些延迟加载的字段。这意味着如果您指示 Jackson@JsonIgnore
在序列化期间忽略它们(使用注释),ORM 将不会获取它们。
推荐阅读
- android-studio - 如何在消息列表中显示联系人姓名或联系人的 display_name
- react-native - 如何让 Detox 点击具有 onPress 的嵌套文本元素?
- codeigniter - 获取 URL Codeigniter 中传递的参数
- php - WP博客页面的PHP文件?
- python - 更新 defaultdict 中的键值对
- javascript - 即使添加了 -webkit- 前缀,Flex 也无法正常工作
- arrays - VBA数组排序问题
- mysql - 十进制的Mysql数据类型
- javascript - 如何添加动态监听器并获取目标值
- javascript - 无法访问 React Typescript 中的 DOM 元素