0
웹 응용 프로그램에 Play 2.0을 사용하고 있습니다. Play의 부동산 시뮬레이션에 대해 알게되었습니다 : http : //www.playframework.org/documentation/1.2.3/model#propertiesPlayframework 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));
}
}
암 : 여기
는 코드인가?
anInstance.field = newValue;
그래서 당신은 인수를 검증하기 위해 직접 세터를 호출해야합니다 : 그것은 표현이 있음을 다시 작성하지 않습니다 1.
재생보다
감사합니다 Schleichardt –