解决 spring mvc 返回ModelAndView设置viewName无效

比如代码是:

package com.spring.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;


@Controller
@RequestMapping("/index")
public class IndexController {
@RequestMapping("/test")
public ModelAndView index(){
ModelAndView mav = new ModelAndView();
mav.setViewName("/index/hello"); 
return mav;
}
}

不管怎么样跳转的jsp都是index文件夹下面的test.jsp。郁闷了很久,结果是引包错误了。

 

package com.spring.controller;

 


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping("/index")
public class IndexController {
@RequestMapping("/test")
public ModelAndView index(){
ModelAndView mav = new ModelAndView();
mav.setViewName("/index/hello"); 
return mav;
}

 

 

}

 

这样就可以了

欢迎访问个人主页: https://tangyuewei.com/

 

你可能感兴趣的:(web开发)