package cn.wycclub.handlers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
@Controller
@RequestMapping("/test")
public class MyController {
@RequestMapping("/third*.do") //资源名称必须以third开头
public ModelAndView doThird(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message","doThird");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
@RequestMapping("/*fourth.do")//资源名称必须以fourth结尾
public ModelAndView doFourth(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message","doFourth");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
@RequestMapping("/*/fifth.do") //路径级数的绝对匹配,既要求在test与fifth.do之间必须有一级路径
public ModelAndView doFifth(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message","doFifth");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
@RequestMapping("/**/sixth.do") //要求在test与sixth.do之间可以包含零到多级路径
public ModelAndView doSixth(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message","doSixth");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
}SpringMVC4 学习笔记(九) 【通配符】
最新推荐文章于 2025-01-15 01:53:56 发布
本文详细介绍了 Spring MVC 中的 URL 映射机制,包括如何通过注解配置不同的请求映射规则,如前缀匹配、后缀匹配、绝对路径匹配及任意层级路径匹配等,并展示了如何使用这些规则实现具体的业务功能。
735

被折叠的 条评论
为什么被折叠?



