spring - Spring数据休眠根据方法序列化项目属性
问题描述
我有个问题。让我们想象一下,我们有一个 Hotel 实体。该实体包含例如id、name、Country 对象引用、主题照片路径和其他照片补丁列表。
我正在使用 Spring Boot JPA + jackson。所以存储库就像...
@Repository
public interface HotelRepository extends CrudRepository<HotelEntity, Long> {
List<HotelEntity> findTop3ByCountryOrderByPriorityDesc(CountryEntity country);
}
有没有可能用一些杰克逊注释实体字段来告诉 Spring boot-“嘿,如果你使用这个存储库方法(例如 findTop3ByCountryOrderByPriorityDesc 方法),只取名称、id 和主题照片。(这种方法将用于所有实体和方法)。像
@JsonSerializeClasses({"top3Hotels", "hotels"})
String name;
以及在 repositorz 中的使用
@JsonSerializeClassesUsage({top3Hotels})
List<HotelEntity> findTop3ByCountryOrderByPriorityDesc(CountryEntitycountry);
(此方法将返回仅包含名称的酒店实体列表)。
注意:它也可以以“消极”的方式工作。因此,如果我用一些“类中的类”注释某个字段,该字段将不会包含在方法的返回对象中,它的注释中没有包含这个“内部类”。
这在杰克逊的 Spring 数据中是否可行?
或者我真的必须返回对象,如果我不想要某些属性,我必须迭代它们并手动“null”它?
谢谢你。
解决方案
推荐阅读
- excel - Power Query 填写空单元格单元新值,然后填写该值
- ios - 将 JSON 提取到 ViewController 并转到第二个 ViewController
- python - python 3.6中安装的库如何在python3.7中使用
- python - WEKA 中的交叉验证和 SMOTE
- java - Gradle 找不到 Apache 公共资源
- java - 向后计数Java的匹配字符数组值
- javascript - 节点流 - 推送读取无意中分成 3 个写入流
- c# - 不知道这些错误来自哪里
- python - 如何根据要解包的变量数量解包不同的值
- c# - 设置 (ref _..) X NotifyOfPropertyChange(() =>...)