我有一个基本的SpringBoot应用程序。使用spring初始化器、jpa、嵌入式tomcat、thymeleaf模板引擎,并将其打包为一个可执行的jar文件。我定义了这个rest方法来更新用户
@PutMapping(path = "/api/users/{id}",
consumes = "application/json",
produces = "application/json")
public ResponseEntity<User> updateUser
(HttpServletRequest request,
@PathVariable long id,
User user) {
System.out.println(user);
saveUser (user)
return ResponseEntity.ok(user);
}
我从控制台调用此方法,使用
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJyaWNhcmQub2xsZUBnbWFpbC5jb20iLCJleHAiOjE1MjgxMTM3NTIsImlhdCI6MTUyNzUwODk1Mn0.QdxabtU1U87pYvyTstT1EG3E6uVpLo2mXCF0FF8iD6acKoAXKl_A0-eV_GrpOFg5FF1qR6B7llI5_USJL85YTQ" -d '{
\"id\":1,\"username\":\"pere.peris@gmail.com\",\"email\":\"pere.peris@gmail.com\",\"firstName\":\"Pere\",\"lastName\":\"PERIS\",\"country\":\"CAT\",\"enabled\":true}' "http://127.0.0.1:2233/iCrypts/api/users/1"
但是在
System.out.println(user);
我从pojo得到的所有值都是空的(!?),但是
id
那是1