admin管理员组文章数量:1397732
I'm having trouble implementing a patch mapping in springboot. This is the structure of the entity I am attempting to update
@Entity
@Component
public class AppUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "user_sequence")
@SequenceGenerator(name = "user_sequence", initialValue = 100, allocationSize = 1)
private int id;
private String username;
private String password;
private double balance;
/* Getter and setter methods here */
}
Here is the patch mapping code
@PatchMapping("/api/user")
public ResponseStructure<AppUser> updateUser(@RequestBody AppUser user) {
//ResponseStructure is only used to parse response data
ResponseStructure<AppUser> responseStructure = new ResponseStructure<AppUser>();
try {
appUserRepository.save(user);
responseStructure.setStatusCode(200);
responseStructure.setMessage("User updated successfully");
responseStructure.setData(user);
return responseStructure;
}
catch (Exception exception) {
responseStructure.setStatusCode(400);
responseStructure.setMessage("Failed to update user: \n" + exception.getMessage());
return responseStructure;
}
}
Here is the body I use when sending the patch request and the subsequent response from Postman
{
"id": 100,
"username": "User3",
"password": "Password1",
"balance": 0.0
}
{
"timestamp": "2025-03-26T23:16:47.331+00:00",
"status": 404,
"error": "Not Found",
"path": "/api/user/"
}
I have personally verified that there is an AppUser with id 100 in my database. Why is it returning a 404 error?
本文标签: spring bootJpaRepository save method returning 404 errorStack Overflow
版权声明:本文标题:spring boot - JpaRepository save method returning 404 error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744120043a2591694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论