restfull详解,参考连接:https://baike.baidu.com/item/RESTful/4406165?fr=aladdin
比如我们访问一个http连接 https://baike.baidu.com/item/RESTful/4406165?fr=aladdin
restfull风格的连接就是:https://baike.baidu.com/item/RESTful/4406165/aladdin
也就是不再带?和key
下面看springboot中使用restfull风格
1.使用@PathVariable注解,路径中参数位置可以随意放,在方法参数注解时位置也可以随意放
@RestController
public class RestfullController {
@Autowired
private StudentService studentService;
@RequestMapping("/boot/resultfull/{id}")
public Object student(@PathVariable("id") Integer id){
return studentService.getStudentByid(id);
}
@RequestMapping("/boot/resultfull/{id}/{name}")
public Object student(@PathVariable("id") Integer id,@PathVariable("name") String name){
StudentModel studentModel = new StudentModel();
studentModel.setId(id);
studentModel.setName(name);
return studentService.getStudentByModel(studentModel);
}
@RequestMapping("/boot/{name}/resultfull/{id}")
public Object student2(@PathVariable("id") Integer id,@PathVariable("name") String name){
StudentModel studentModel = new StudentModel();
studentModel.setId(id);
studentModel.setName(name);
return studentService.getStudentByModel(studentModel);
}
}
参考:https://www.jianshu.com/p/a94c38532f82