我想映射春天mvc控制器到根(/**
)路径(而不是子文件夹,如“/东西”),同时使mvc:resources
异常(打开到另一种方法) 。春天mvc网站的根(“/”)
这应该是该框架的基础知识,但显然是要求它的一个非常复杂的东西。
我app-servlet.xml
有这些明显的映射例外:
<mvc:resources mapping="/favicon.ico" location="/favicon.ico" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" />
我有此控制器:
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/**")
public class MainController {
@RequestMapping(method = RequestMethod.GET)
public String service(final HttpServletRequest request) {
final String servlet_path = request.getServletPath();
System.out.println(String.format("%s %s", new Date().toString(), servlet_path));
return "test";
}
}
现在,当我打 “/” 或 “/测试” 或“/测试/页“我得到如下输出:
Fri Aug 03 00:22:12 IDT 2012/
Fri Aug 03 00:22:13 IDT 2012 /favicon.ico
..看到了吗? service()
即使在明确排除的情况下也会被呼叫/favicon.ico
!
现在我想在XML上有@Controller
的“优先权”,但是,我该如何使排除工作?
一个简单的要求 - 网站上有“/”。
P.S This answer回答一个非常类似的问题。
另一个注意:这个问题不是关于tomcat的上下文。
您的解决方案是指一个单一的URL(“/” - >“家”)。我需要它是一张通配符。如果你可以慷慨解释如何提高'@ RequestMapping'的'mvc:resources'的优先级,那么我猜测,它会解决它。谢谢! – Poni 2012-08-02 22:19:45
添加更新 – 2012-08-02 22:41:33
工作 - 谢谢Biju! – Poni 2012-08-02 22:51:16