springMVC简易框架学习(三)
https://blog.csdn.net/qq_36760873/article/details/100037527(一)
https://blog.csdn.net/qq_36760873/article/details/100037599(二)
5.注解形势下访问自定义方法
在配置文件中开启Spring注解和mvc注解
context:annotation-config/
<context:component-scan base-package=“com.sram”></context:component-scan>
mvc:annotation-driven/
在需要访问的方法上标明注解
@Controller
@RequestMapping("/MyController")
public class MyController{
@RequestMapping(value = “/add”)
public ModelAndView add(HttpServletRequest request,HttpServletResponse response){
System.out.println(“进入控制器+add”);
ModelAndView mv = new ModelAndView(“index”);
return mv;
}
}
6.RuequestMapping详解
//给一个方法映射多个请求路径
@RequestMapping(value = {“add01”,“add02”})
public ModelAndView add(HttpServletRequest request,HttpServletResponse response){
System.out.println(“进入控制器+add”);
ModelAndView mv = new ModelAndView(“index”);
return mv;
}
//rest风格接收参数
@RequestMapping(“add/{id}/{username}”)
public ModelAndView