<mvc:view-controller>標簽
如果我們有些請求只是想跳轉頁面,不需要來后台處理什么邏輯,我們無法在Action中寫一個空方法來跳轉,直接在中配置一個如下的視圖跳轉控制器即可(不經過Action,直接跳轉頁面)
在jsp頁面中寫入:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>首頁</title> </head> <body> <a href="/hello_world">Hello World</a> <br /> </body> </html>
在配置文件寫入:
<mvc:view-controller path="/" view-name="index2" />
在controller類寫入:
@RequestMapping("/hello_world") public String helloWorld(Model model){ model.addAttribute("msg","hello world"); return "hello_springmvc"; }
配置成功后,發現你訪問其他的頁面會失敗並且idea出現這個警告
原因:如果沒有<mvc:annotation-driven/>,那么所有的@Controller注解可能就沒有解析,所有當有請求時候都沒有匹配的處理請求類,就都去<mvc:default-servlet-handler/>即default servlet處理了。