1.controller里注解的写法
1.1基础写法
@Controller//引用Controller
public class helloController {
@RequestMapping(value = "/users",method = RequestMethod.GET)//请求头以及请求方式
@ResponseBody//相应主体
public String save(){
System.out.println("user save...");
return "{'module':'user save'}";
};
@RequestMapping(value = "/users/{id}",method = RequestMethod.DELETE)
//如果有参即可在请求头加入腰穿的参数同时需要在方法里加入@PathVariable
@ResponseBody
public String delete(@PathVariable Integer id){
System.out.println("user delete..."+id);
return "{'module':'user delete'}";
};
@RequestMapping(value = "/users/{id}",method = RequestMethod.PUT)
@ResponseBody
public String update(@PathVariable Integer id){
System.out.println("user update..."+id);
return "{'module':'user update'}";
};
}
1.2简化写法
@RestController
//将@Controller与 @ResponseBody简化成一个
@RequestMapping("/books")
//直接开头加入请求头
public class jianhua {
//简化版本的 @RequestMapping(value = "/users",method = RequestMethod.GET)
@GetMapping
public String save(){
System.out.println("user save...");
return "{'module':'user save'}";
};
//简化版本的 @RequestMapping(value = "/users/{id}",method = RequestMethod.DELETE)
@DeleteMapping("/{id}")
public String delete(@PathVariable Integer id){
System.out.println("user delete..."+id);
return "{'module':'user delete'}";
};
@PutMapping("/{id}")
public String update(@PathVariable Integer id) {
System.out.println("user update..." + id);
return "{'module':'user update'}";
}
}
标签:module,springboot,第一天,System,笔记,public,user,println,id From: https://www.cnblogs.com/jinghong-wang/p/16948624.html