restful风格下springmvc的默认欢迎页配置

项目使用restful风格,默认全局拦截/请求,如果再web.xml里面<welcome-file-list>直接配置index.jsp/index.html会被当成静态资源拦截,如何把@RequestMapping设置成首页,解决方案:

@Controller
@RequestMapping("/router")
public class RouterController {

    /**
     * 管理员登陆
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String admin(){
        return "admin/login";
    }

在web.xml添加

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/router/login</url-pattern>
</servlet-mapping>

<!--首页-->
<welcome-file-list>
    <!--这里没有"/"-->
    <welcome-file>router/login</welcome-file>
</welcome-file-list>

猜你喜欢

转载自blog.csdn.net/weixin_42795831/article/details/81777515