作用:@PathVariable 映射 URL 绑定的占位符
- 带占位符的 URL 是 Spring3.0 新增的功能
- 通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“) 绑定到操作方法的入参中
/**
* @author: 独行老僧
* @description: 查找用户
* @date: 2019/10/29 07:19
*/
@RestController
public class UserController {
@Autowired
private UserRepository userRepository;
@GetMapping("getUser/{id}")
public User findById(@PathVariable("id") Long id) {
User findOne = this.userRepository.findOne(id);
return findOne;
}
}