pom.xml에
1 2 3 4 5 6 7 8 9 10 11 12 | <!-- validation --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.2.0.Final</version> </dependency> | cs |
추가
UserController 에 메서드에 @Valid 추가,바인딩 추가, 모델추가
1 2 3 4 5 6 7 8 9 10 11 12 13 | public String join( @ModelAttribute @Valid UserVo userVo, BindingResult result, Model model) { if(result.hasErrors()) { // List<ObjectError> list = result.getAllErrors(); // for(ObjectError error : list) { // System.out.println(error); // } model.addAttribute(result.getModel()); return "user/join"; } | cs |
UserVo에 필요한 유효성검사들 추가
1 2 3 4 5 6 7 8 9 10 11 12 | import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.NotEmpty; public class UserVo { private long no; @NotEmpty @Length(min=2, max=8) private String name; @NotEmpty @Email private String email; | cs |
default값도 있지만
파일추가후
1 2 3 4 | NotEmpty.userVo.name = \uC774\uB984\uC774 \uBE44\uC5B4 \uC788\uC2B5\uB2C8\uB2E4. Length.userVo.name = \uC774\uB984\uC774 (2~8)\uAE00\uC790\uAC00 \uB4E4\uC5B4\uAC00\uC57C\uB429\uB2C8\uB2E4 NotEmpty.userVo.email = \uC774\uBA54\uC77C\uC774 \uBE44\uC5B4 \uC788\uC2B5\uB2C8\uB2E4 Email.userVo.email = \uC774\uBA54\uC77C \uD615\uC2DD\uC5D0 \uB9DE\uAC8C \uC785\uB825\uD574\uC8FC\uC138\uC694. | cs |
자동 암호화가 됨. - 안될시 윈도우 프로퍼티 텍스트 utf-8로 바꿔줌
728x90
'풀스택 > Spring' 카테고리의 다른 글
2. Dnamic web project 생성후 maven project로 변경 및 설정 (0) | 2019.03.22 |
---|---|
1. spring 설명 (0) | 2019.03.22 |
mysite3예제 user&guest 부분 servlet-jsp에서 spring로 (0) | 2019.02.25 |
spring에서의 예외처리 (0) | 2019.02.23 |
ViewResolver 설정 (0) | 2019.02.23 |
댓글