Scala 的 @BeanProperty 用于选项
是否可以为可选变量实现 BeanProperty ?与 JPA 配合使用会很有用。
那就太好了:
@BeanProperty var status: Option[String]
如果将以下方法添加到类中,
def setStatus(s: String) { status = Some(s) }
def getStatus: String = status.get
Is it possible to implement BeanProperty for Optional variables? It would be useful with JPA.
It would be great if:
@BeanProperty var status: Option[String]
would add the following methods to the class:
def setStatus(s: String) { status = Some(s) }
def getStatus: String = status.get
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是不是,但有一个简单的解决方法可以两全其美:
请注意,JPA 不理解
Option[T]
。顺便说一句,如果您使用字段访问而不是 JPA 中的 getter/setter 访问,则甚至不需要@BeanProperty - JPA 提供程序将扫描 Java 字段。Unfortunately not, but there is a simple workaround that brings best of both worlds:
Note that JPA does not understand
Option[T]
. BTW if you use field-access as opposed to getter/setter access in JPA,@BeanProperty
isn't even needed - the JPA provider will scan Java fields instead.