Spring MVC 项目No mapping found for HTTP request with URI

/**
     * 跳转到登录页
     * http://localhost:8080/web-0.0.1-SNAPSHOT/index/index
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/index", method = { RequestMethod.GET })
    public ModelAndView index(HttpSession httpSession) {
    	
    	ModelAndView mav = new ModelAndView();
    	if(checkUser(httpSession)) {
            mav.setViewName("statis/index");
    	}else {
    		mav.setViewName("index/index");//使用简写进行jsp页面跳转,需要在applicationContext-mvc.xml文件中配置跳转到jsp视图的前后缀
    	}
    	return mav;
    }

 

Controller层跳转jsp视图,如果使用简写方式跳转,则需要在spring的xml中配置jsp的前后缀。

applicationContext-mvc.xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<beans ...>

    

<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass"

  value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/views/" />

<property name="suffix" value=".jsp" />

</bean>

 

<!-- 静态资源文件,不会被Spring MVC拦截 -->

<mvc:resources location="/" mapping="/**/*.html"/>

<mvc:resources location="/" mapping="/**/*.js"/>

<mvc:resources location="/" mapping="/**/*.css"/>

<mvc:resources location="/" mapping="/**/*.png"/>

<mvc:resources location="/" mapping="/**/*.jpg"/>

<mvc:resources location="/" mapping="/**/*.gif"/>

</beans>

 

参考:https://blog.csdn.net/wxtcstt/article/details/79424986

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值