controller的使用

@controller:处理http请求

@restcontroller:==@controller和@requestbody

@requestmapping配置url映射 

(1)都能访问到该方法:@RequestMapping(value = {"/demo1","/demo2"},method = RequestMethod.GET)

(2)在整个controller上指定一个路径,拼接访问。

传参数

(1)@PathVariable

举例:

@RequestMapping(value = "demo/{id}",method = RequestMethod.GET)

@RequestMapping(value = "{id}/demo",method = RequestMethod.GET)

public String Say(@PathVariable("id") String id){
//Man man=new Man();
// man.setAge("25");
// man.setName("hahahaha");
return "id:"+id;
}
(2)@RequestParam还可以设置默认值
@RequestParam(value = "id",required = false,defaultValue = "0")
// @RequestMapping(value = "/demo",method = RequestMethod.GET)
@GetMapping("/demo")
 @PostMapping("/")组合注解
 
原文地址:https://www.cnblogs.com/wmm1117/p/8466477.html