상세 컨텐츠

본문 제목

자바 프로젝트 Validation 방법

개발

by 동동주1123 2011. 10. 16. 14:55

본문



http://openframework.or.kr/framework_reference/spring/ver2.x/html/validation.html



1 선언적 validation , javax.validation
import javax.validation.*;

import spring.validation.*

class Customer {

       @NotNull
       String name;

       @NotNull
       @LargeThan(0)
       @SmallThan(120)
       Integer age;
}




Web Browser -> Controller -> Customer

ModelAndView updateCustomer(HttpServletRequest req, HttpServletResponse res, Cusotmer c ){
//      Cusotmer c = new Customer();
//      bind(req, c);


}



2. 절차적
CusotmerMgmtBiz <- Customer  {

       javax.validation.Validator validator;

       - Customer name must be not null
       - Customer age must be larger than 0
       updateCustomer(Customer c){
               assert c.name != null;
               assert c.age > 0;

               // business logic
       }


3. 절차적 확장
       // assert 확장
       addCustomer(Customer c){
               Validator.validate(c, "name", new MaxLength(15));
               Validator.validate(c, "name", new MaxLength(15));
               Validator.validate(c, "name", new MaxLength(15));
               Validator.validate(c, "name", new MaxLength(15));
               Validator.validate(c, "name", new MaxLength(15));

       }



4. AOP
       registerCustomer(Customer c){
               validator.validate(c);
               // business logic
       }

       @RequiredValid
       unregisterCustomer(Customer c){
               // business logic
       }
}



AOP for @RequiredValid and Biz, Service  {
       validator.validate(c);
}



DB -> DAO -> Customer

관련글 더보기