MCPcopy Create free account
hub / github.com/castello/spring_basic / RegisterController

Class RegisterController

ch3/RegisterController.java:20–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import org.springframework.web.bind.annotation.RequestMethod;
19
20@Controller // ctrl+shift+o 자동 import
21@RequestMapping("/register")
22public class RegisterController {
23
24 @InitBinder
25 public void toDate(WebDataBinder binder) {
26 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
27 binder.registerCustomEditor(Date.class, new CustomDateEditor(df, false));
28 binder.setValidator(new UserValidator()); // UserValidator를 WebDataBinder의 로컬 validator로 등록
29 // List<Validator> validatorList = binder.getValidators();
30 // System.out.println("validatorList="+validatorList);
31 }
32
33 @GetMapping("/add")
34 public String register() {
35 return "registerForm"; // WEB-INF/views/registerForm.jsp
36 }
37
38 @PostMapping("/add")
39 public String save(@Valid User user, BindingResult result, Model m) throws Exception {
40 System.out.println("result="+result);
41 System.out.println("user="+user);
42
43 // User객체를 검증한 결과 에러가 있으면, registerForm을 이용해서 에러를 보여줘야 함.
44 if(result.hasErrors()) {
45 return "registerForm";
46 }
47
48 // 2. DB에 신규회원 정보를 저장
49 return "registerInfo";
50 }
51
52 private boolean isValid(User user) {
53 return true;
54 }
55}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected