1.@RequestMapping
设置控制器类/请求处理方法的访问路径的
@RequestMapping可以作用在java类上,表示配置这个java类的访问路径;
package com.wangxing.springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/hello")
public class HelloController{
@RequestMapping("/test1.do")
public ModelAndView testRequest(){
ModelAndView mav=new ModelAndView();
mav.addObject("info","hello,网星软件");
mav.setViewName("test.jsp");
return mav;
}
}
http://localhost:8080/spingmvc2/hello/test1.do
如果控制器类中没有@RequestMapping("/hello"),那么我们要访问请求处理方法就可以直接使用请求处理方法上@RequestMapping("/test1.do")的访问路径。
package com.wangxing.springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController{
@RequestMapping("/test1.do")
public ModelAndView testRequest(){
ModelAndView mav=new ModelAndView();
mav.addObject("info","hello,网星软件");
mav.setViewName("test.jsp");
return mav;
}
}
http://localhost:8080/spingmvc2/test1.do
@RequestMapping也可以作用在请求处理方法上,表示配置这个请求处理方法的访问路径。
@RequestMapping的常用的属性:
1.value表示设置访问路径[可以省略]
@RequestMapping(value = "/test1.do") 可以省略