gpt4 book ai didi

playframework-2.0 - 玩!框架 2.+ 在 @ManyToOne 外键上使用 Ebean @Constraints.Required

转载 作者:行者123 更新时间:2023-12-04 07:48:26 26 4
gpt4 key购买 nike

是否可以轻松定义外部字段的约束?

示例:我有一个 Entity1 和一个 Entity2。 Entity1 有一个字段 entity2_id,它是建立连接的外键。但是,这在简单字段上的效果不如 @Required 约束,例如 String title :

这不起作用:

@ManyToOne
@JoinColumn(name = "entity2_id")
@Required
public Entity2 entity2;

这有效:
@Required
public String title;

我知道表单 validate()方法。有没有更简单的方法?最好是在 View 中的特定字段上强制错误的方法,而不将消息作为参数传递给 View 。

谢谢

最佳答案

我在几个 ManyToOne 关系上使用了 Required 注释,这个工作完美。

与您的代码的一个区别是我不使用的 JoinColumn 注释。

I'm aware about the form form validate() method. Is there a simpler way? preferrably a way that will force the error on the specific field in the view without passing the message to the view as a parameter.



我知道的唯一解决方案是创建自己的注释。

关于playframework-2.0 - 玩!框架 2.+ 在 @ManyToOne 外键上使用 Ebean @Constraints.Required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945384/

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