使用 Lombok 为带注释的代码生成 Java getter/setter

发布于 2024-09-18 17:08:02 字数 275 浏览 2 评论 0原文

我使用 Project Lombok 为 Java 类的所有字段自动生成 getter 和 setter 方法。

当某个字段使用例如 @XmlTransient 进行注释时,该注释不会传播到生成的 getter/setter 方法,因此在生成的代码中不会显示任何效果。有没有办法将自动 getter/setter 生成与进一步的注释结合使用?

I use Project Lombok to automatically generate getter and setter methods for all fields of a Java class.

When a field is annotated with e.g. @XmlTransient, the annotation is not propagated to the generated getter/setter methods, thus in the resulting code it does not show any effect. Is there a way to use automatic getter/setter generation in conjunction with further annotations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2024-09-25 17:08:02

我认为将注释传播到 getter/setter 方法在一般情况下不起作用。例如,您知道如果字段和 bean 属性都用 @XmlElement 注释会发生什么吗?对于 JAXB 注释,我建议在字段上使用 @XmlAccessorType(XmlAccessType.FIELD)

I don't think propagating annotations to getter/setter methods would work in the general case. For example do you know what would happen if both the field and the bean properties were annotated with @XmlElement? For JAXB annotations I would suggest using @XmlAccessorType(XmlAccessType.FIELD) on the field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文