gpt4 book ai didi

java - Json 忽略实体中的集合

转载 作者:太空宇宙 更新时间:2023-11-04 14:20:22 24 4
gpt4 key购买 nike

我使用@JsonIgnore来忽略我的实体中的一些集合,以ajax作为json元素发送。

为了生成映射类,我使用 hibernate 工具

我的问题是,我经常更改数据库架构,因此当我再次生成实体时,我会丢失 @JsonIgnore 注释。

那么有没有解决方案可以自动添加它们或将它们添加到单独的文件中?

最佳答案

您可以dynamically add annotations at runtime

  1. 您需要使用 @PostConstruct init 方法添加 Spring Bean。

  2. 在 init 方法中,您可以动态地将实体添加到要忽略的实体类属性中。

关于java - Json 忽略实体中的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27258899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com