我将旧的servlet应用程序转换为Spring 3.1。在这个过程中,一些URL现在已经过时了。我们的网络出现了一些问题,无法马上解决。我的老板不想相信他们的重定向将始终运作。所以,她让我把自己的重定向到webapp中。Spring-MVC 3.1:如何映射带有斜线的URL?
所有的工作都很好,除了如果一个URL有一个尾部的斜线,Spring 3.1将找不到处理它的Controller类的函数。
http://blah.blah.blah/acme/makedonation被发现,映射和处理
http://blah.blah.blah/acme/makedonation/不
这里是我使用来处理我的旧有的网址
import org.springframework.stereotype.Controller;
import org.springframework.validation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.apache.log4j.Logger;
@Controller
public class LegacyServletController {
private static final Logger logger = Logger.getLogger(LegacyServletController.class);
// Redirect these legacy screns "home", the login screen via the logout process
@RequestMapping({"makeadonation","contact","complain"})
public String home() {
logger.debug("started...");
return "redirect:logout";
}// end home()
}// end class LegacyServletController
我用Google搜索了一圈,发现控制器类这个堆栈溢出post,提供了几个建议,但我是新来的Spring,并没有足够的理解它来实现一些suggestio纳秒。这其中尤其是听起来像这将是非常适合我的需求:
春季3.1 RequestMappingHandlerMapping允许您设置一个 “useTrailingSlashMatch”属性。默认情况下它是真的。我认为 它转换为false将解决您的问题,
会有人给我如何说,引用我说,有这样一个例子的URL一个基本的例子(我曾与谷歌没有运气)或点我更好的主意?
感谢很多提前 史蒂夫
我我看到了这样的解决方案'@RequestMapping(value = {“/ search /”,“/ search”},method = RequestMethod.GET)' – basil 2016-08-08 06:29:14