例如,我想用2个不同的模板创建一个404页面,一个是pc,另一个是mobile.and我正在使用user-agent来计算它。我正在使用*来匹配所有url,除了正常的url我的网站自己。
但它只能匹配: www.abc.com/notfound1
它无法匹配www.abc.com/notfound1/notfound2,etc ...
我想匹配url路径控制器没有,怎么做,谢谢。
以下观点,我想用一个词来形容它,任何表示*符号:
@RequestMapping(value =“any”,method = RequestMethod.GET)
@RequestMapping(value =“any / any”,method = RequestMethod.GET)
@RequestMapping(value =“any / any / any”,method = RequestMethod.GET)
@RequestMapping(value = "*", method = RequestMethod.GET)
public ModelAndView notfound() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("error");
String useragent = servletRequest.getHeader("user-agent");
if (StringUtils.isNotBlank(useragent)) {
boolean isMobile = CheckMobile.check(useragent);
if (isMobile) {
modelAndView.setViewName("errormobile");
}
}
return modelAndView;
}
答案 0 :(得分:0)
您可以尝试:
@RequestMapping(value={"/notfound1/notfound2", "/notfound3", "/notfound4"})
OR
您可以使用JS控制视图取决于设备分辨率。 我仍然不知道你到底想做什么。