我正在为 web 应用程序使用 Play 2.0。了解Play的属性模拟:http://www.playframework.org/documentation/1.2.3/model#properties
当我在示例应用程序上尝试相同的操作时,setter 的验证没有被调用。
我在调试模式下重新运行应用程序并将断点放在 Product 类的 Setter 方法上,但它没有被执行。
这是代码片段:
public class Product {
public String name;
public Integer price;
public void setPrice(Integer price) {
if (price < 0) {
throw new IllegalArgumentException("Price can’t be negative!");
}
this.price = price;
}
}
public class Application extends Controller {
public static Result index() {
Product p=new Product();
p.name="Test";
p.price=-1; //I am expecting that code will throw IllegalArgumentException but its not
return ok(index.render(p.name));
}
}
我在这里错过了什么吗?