最近遇到了一個問題:表單:
提交后進入到controller:
@RequestMapping("student/findStudents.do")
public String findStudents(){
...
return "/index";? //這種方法可以正常返回到index.jsp頁面
}
但是用下面的方法路徑不對:
@RequestMapping("student/findStudents.do")
public ModelAndView findStudents(){
ModelAndView mav = new ModelAndView("/index");
return mav;
}
為什么返回路徑不是構造函數的參數指定的路徑,而是請求路徑:student/student/findStudents2
使用modelandview時返回的路徑會添加你上一級路徑,和你在配置文件配置好的路徑不一樣。原因就是包倒錯了,springMVC中的modelandview有兩個包,一個是org.springframework.web.servlet.ModelAndView,另一個是org.springframework.web.portled.ModelAndView這個包,就是導致我們多加一個路徑的包,因此使用第一個包就可以解決我們的問題了。