我正在使用for应用程序的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));
}
}我是不是漏掉了什么?
发布于 2012-10-07 06:17:47
播放2与播放1的行为不同。
它不会重写表达式:
anInstance.field = newValue;所以你必须直接调用setter来验证参数。
来源:https://groups.google.com/forum/#!topic/play-framework/S8DHAcYHh-A
https://stackoverflow.com/questions/12763959
复制相似问题