package zhang.springmvc.hander;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RequestMapping("/springmvc")
@Controller
public class TestSpringmvc {
private static final String SUCCESS="success";
//处理delete请求
@RequestMapping(value="/testdelete/delete/1",method=RequestMethod.DELETE)
public String testdelete(@PathVariable("id") Integer id){
System.out.println("testdelete:"+id);
return SUCCESS;
}
//处理put请求
@RequestMapping(value="/testput/put",method=RequestMethod.PUT,params={"username","password"})
public String testput(){
System.out.println("testput");
return SUCCESS;
}
//处理get请求
@RequestMapping(value="/testget/get",method=RequestMethod.GET)
public String testget(){
System.out.println("test get");
return SUCCESS;
}
//处理post请求
@RequestMapping(value="/testpost/post/{id}",method=RequestMethod.POST)
public String testpost(@PathVariable("id") Integer id){
System.out.println("test post:"+id);
return SUCCESS;
}
/**
* 可以映射url中的占位符到参数中
* @param id
* @return
*/
@RequestMapping(value="/testPathvariable/{id}")
public String pathvariable(@PathVariable("id") Integer id){
System.out.println("testpathvariable:"+id);
return SUCCESS;
}
/**
* 支持通配符
* @return
*/
@RequestMapping("/ABC/*/testantpath")
public String testantPath(){
System.out.println("testantpath");
return SUCCESS;
}
/**
* 了解内容:用来指定请求参数和请求头
* @return
*/
@RequestMapping(value="testparamsAndHeader" ,params={"username","age!=23"})
public String testparamsAndHeader(){
System.out.println("testparamsAndHeader");
return SUCCESS;
}
/**
* 使用method来指定处理请求的方式,可以让处理的请求更加的精确
* @return
*/
@RequestMapping(value="/testMethod",method=RequestMethod.POST)
public String testMethod(){
System.out.println("testmethod");
return SUCCESS;
}
/**
* 1.@RequestMapping:可以用来修饰类也可以用来修饰方法
* 1).修饰方法处理的是相对web应用的根目录
* 2).修饰类后,方法的url是相对类的路径,而类是相对web应用的根目录.
* @return
*/
@RequestMapping("/helloword")
public String testrequestMapping(){
System.out.println("testrequestmapping");
return SUCCESS;
}
}
Springmvc中的requestMapping注解的使用
最新推荐文章于 2024-09-11 16:29:15 发布