카테고리 없음
[Spring] Redirect방식으로 보내기
박강균 IT
2021. 4. 12. 17:33
package com.creat.com;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class StudentController {
@RequestMapping("/studentForm")
public String studentFrom() {
return "create/createPage";
}
@RequestMapping("/create")
public String studentCreate(@ModelAttribute("student") Student student,BindingResult result) {
String page="create/createDonePage";
StudentValidator vaildator= new StudentValidator();
vaildator.validate(student, result);
if(result.hasErrors()) {
page="create/createPage";
}
return page;
}
}
ㄱ
그냥 Redirect방식으로 보내고 싶은 부분의 url을
if(result.hasErrors()) {
page="redirect:/studentForm";
}
아래와 같이 맵핑된 부분으로 바꿔주면 된다.
감사합니다.