论坛首页 Java企业应用论坛

[SpringMVC]定义多个前缀映射的问题

浏览 2621 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2009-10-22  
我在web.xml里面定义多个dispatch-servlet的前缀映射,像下面这样
<!-- Servlets -->
	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>/guestbook/*</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>/note/*</url-pattern>
	</servlet-mapping>

在controller里面分别有对应的controller
@Controller
@RequestMapping(value = "/note")
public class Note {
	@RequestMapping(value = "/show", method = RequestMethod.GET)
	public String show(Model model) {
		return "note/show";
	}
...
}

@Controller
@RequestMapping(value = "/guestbook")
public class Note {
	@RequestMapping(value = "/show", method = RequestMethod.GET)
	public String show(Model model) {
		return "guestbook/show";
	}
...
}


当有多个前缀映射的时候,springmvc就不认得了?
看起来像前缀映射时springmvc取得的参数是url-pattern里面的*的部分。

盼高手解决,谢谢
   发表时间:2009-10-22   最后修改:2009-10-22
还是自己解决了...

<servlet-mapping>
	<servlet-name>dispatcher</servlet-name>
	<url-pattern>/</url-pattern>
</servlet-mapping>



干脆全部都映射到dispatcher-servlet好了,最多写多个controller映射"/"根地址index
@Controller
public class IndexRedirect {
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index() {
		return "index";
	}
|


变相解决了-,-
0 请登录后投票
   发表时间:2009-12-23  
<!-- Servlets --> 
    <servlet> 
        <servlet-name>dispatcher</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
        <servlet-name>dispatcher</servlet-name> 
        <url-pattern>/guestbook/*.do</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
        <servlet-name>dispatcher</servlet-name> 
        <url-pattern>/note/*.html</url-pattern> 
    </servlet-mapping> 


在controller里面分别有对应的controller
Java代码
@Controller 
public class Note {  
    @RequestMapping("/note.do")
    public String show(Model model) {  
        return "note/show";  
    }  
...  


Java代码
@Controller    
public class Note {    
    @RequestMapping("/guestbook.html")
    public String show(Model model) {  
        return "guestbook/show";  
    }  
...  

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics