我发现在这样的 Spring 3.0.6 控制器中是可以的:
@Controller
@RequestMapping(value = "/dialog")
public class DialogController {
@RequestMapping(value = "/redirected.view")
public ModelAndView redirected() {
System.out.println( "DialogController.redirected()" );
final ModelAndView mav = new ModelAndView( "redirected" );
return mav;
}
@RequestMapping(value = "/form.view")
public Object form() {
System.out.println( "DialogController.form()" );
return createModel();
}
private ModelAndView createModel() {
final ModelAndView mav = new ModelAndView( "redirect:redirected.view" );
return mav;
}
}
注意...的Object
返回类型form()
当我将 Spring 版本更改为 3.1.2 时,它返回 404 - 它找不到
WEB-INF/jsp/dialog/form.jsp
,这很奇怪。
是的,我正在使用 viewResolver
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
原始代码中的方法更复杂
@RequestMapping(value = "/search.form", method = RequestMethod.POST)
public Object submit( @Valid @ModelAttribute("sequentialSearch") final SequentialSearchData searchObject,
final BindingResult bindingResult, final Model model, final HttpSession session ) throws Exception {
...
}
可能这就是为什么没有显示错误的原因......
我在那里Object
,因为我返回了,String
或者ModelAndView
,现在我总是返回ModelAndView
,所以我可以更改返回类型并且它可以工作。