【发布时间】:2019-04-28 09:30:08
【问题描述】:
我已经尝试过这段代码,但它不断地给我一个错误。
@GetMapping("/findbyid/{id}")
public Optional<UserDTO> getUserByID(@PathVariable Integer id){
return userservices.finBYID(id);
}
@Override
public Optional<UserDTO> finBYID(Integer id) {
return userrepository.findById(id);
}
结果是:
{
"timestamp": "2019-04-28T04:53:00.225+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/user/find/1"
}
【问题讨论】:
-
响应中的路径与您在映射中设置的不匹配。请仔细检查您是否向正确的端点发出请求,然后提供minimal reproducible example。请注意,传统的 RESTful API 看起来像
/users/{id}。
标签: java maven spring-boot