[英]Form Validation in Play framework
I am creating a Play application with Play 2.3 in Java. 我正在用Java的Play 2.3创建一个Play应用程序。
I'm trying to use Form for handling POST request with JSON body. 我正在尝试使用Form处理带有JSON正文的POST请求。
My problem is that if my JSON is a simple object with only Strings or Floats attribute, it works well. 我的问题是,如果我的JSON是仅具有Strings或Floats属性的简单对象,则它会很好地工作。 But if I put some of Object imbrication, it continue to bind the request corectly but don't do the Constraints validation in nested objects. 但是,如果我放一些Object简化,它会继续核心地绑定请求,但不对嵌套对象进行Constraints验证。
Here an exemple of what I'm trying to do : 这是我正在尝试做的一个例子:
public class PairRequest
{
@Required
public String epc;
@Required
public RequestProduct product;
}
public class RequestProduct
{
//Product data
@Constraints.Required
private String productCode;
@Constraints.Required
public Brand brand;
@Constraints.Required
private String furniture;
}
@Entity
public class Brand extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
@Column(length = 250)
@Constraints.Required
public String name;
@Column(nullable = true, length = 512)
public String regex;
}
Have I missed something ? 我错过了什么吗? It's weird because I think it was working during first times... But I can't be sure. 这很奇怪,因为我认为它是第一次运行。但是我不确定。
如此@Valid
指出的,不仅需要批注@Required
还需要@Valid
用于复杂对象: 自动绑定复杂(JSON)表单数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.