Spring Boot的URL映射
@RequestMapping的value属性用于匹配URL映射,value支持简单表达式:
@RequestMapping注解提供了method参数指定请求的Method类型,包括RequestMethod.GET、RequestMethod.POST、RequestMethod.DELETE、RequestMethod.PUT等值,分别对应HTTP请求的Method
@RestController
@RequestMapping("/user")
public class UserRestController {
@RequestMapping("/getuser/{id}")
//@PathVariable注解作用在方法参数中,用于表示参数的值来自URL路径
public String getUser(@PathVariable("id") Long id)
{
User user = new User();
user.setFirstname("Donald");
user.setLastname("Xeong");
user.setAge(40);
returnid.toString() + "\t" + user.getAge()+ "\t" + user.getFirstname() + "\t"+ user.getLastname();
}
@RequestMapping(value = "/getData",method = RequestMethod.GET)
public String getData() {
return"requestMethod Get";
}
@RequestMapping(value = "/postData",method = RequestMethod.POST)
public String postData()
{
return"RequestMethod Post";
}
}
页:
[1]