편집 : 사람이 아래의 안내에 따라 문제가있는 경우,이처럼 쉬운 방법을 사용하는 것이 좋습니다 : 난 아직도 다음있어 https://www.youtube.com/watch?v=yaxUV3Ib4vM리디렉션
이 튜토리얼 : spring-mvc-radiobutton-and-radiobuttons-example 나는 지금까지이 컨트롤러를 만들었습니다
@RequestMapping(value = "add", method = RequestMethod.GET)
public String add(Model model) {
MyObject object = new MyObject();
object.setParameter("fake parameter");
model.addAttribute("add", object);
initModelList(model);
return "add";
}
@RequestMapping(value = "add", method = RequestMethod.POST)
public String add(@ModelAttribute("add") @Validated MyObject object, BindingResult result, Model model) {
model.addAttribute("add", object);
String returnVal = "redirect:/add/object";
if(result.hasErrors()) {
initModelList(model);
returnVal = "add";
} else {
model.addAttribute("add", object);
}
return returnVal;
}
@RequestMapping(value = "/add/object", method = RequestMethod.POST)
public String addObject(
@ModelAttribute MyObject object,
ModelMap model) throws DatatypeConfigurationException {
try{
...marshalling results in xml output
...inserting it in database
...showing the result
return "objectResult";
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
물론이 솔루션이 작동하지 않습니다, 리디렉션 유형의 GET의 때문이다. 내가 그렇게처럼 함께 마지막 두 가지 방법을 융합하는 시도했다 :
@RequestMapping(value = "add", method = RequestMethod.POST)
public String add(@ModelAttribute("add") @Validated MyObject object, BindingResult result, Model model)
throws DatatypeConfigurationException {
model.addAttribute("add", object);
String returnVal = "objectResult";
if(result.hasErrors()) {
initModelList(model);
returnVal = "add";
} else {
model.addAttribute("add", object);
}
try{
...mashalling etcetera
return returnVal;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
를하지만 그 방법으로 유효성 검사가 작동하지 않습니다. 이 문제를 해결하는 방법을 모르겠다. 스프링 밸리데이터를 사용하고 싶지만 사용할 수 없다면 프로젝트를 퇴색시킬 것이다. 수치 스럽다. 사람이 같은 가이드 다음과 같은 문제가있는 경우
를 업데이트 neeed하지 않는 이유는 무엇입니까? 리다이렉트는 패턴 [post-redirect-get] (https://en.wikipedia.org/wiki/Post/Redirect/Get) 일 수도 있습니다. 그래서 작동하지 않는 것은 확실하지 않지만, 당신의 이해와 관련이 있다고 생각합니다. (이미 코드를 살펴보면 처음에는 해킹으로 가득차 있습니다.) –
내 컨트롤러에서 RequestMethod.POST로 매핑 한 경우에도 "Request method '가 지원되지 않습니다."라는 메시지가 표시되므로 리디렉션이 작동하지 않습니다. 나는 가이드와 다른 것들을 이해하지 못했을 가능성이있다. 왜냐하면 나는 일종의 초보자이기 때문이다. – tina
글쎄, 내가 분명히하는 메시지는 그렇지 않다 ... 리다이렉트는 당신이 GET을 말한 것처럼, 그러나 당신은 그것을위한 방법이 없다. 그렇다면 GET을 처리 할 수있는 것이 없으므로 그 메시지를 얻을 것입니다. –