Rest 方法没有得到正确的数据

Rest method does not get the proper data

我有一个基本的 Spring 启动应用程序。使用 Spring 初始化程序、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。我已经定义了这个 Rest 方法来更新 User

@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

@RequestBody 缺少注释

public ResponseEntity<User> updateUser
                                (HttpServletRequest request, 
                                @PathVariable long id,
                                @RequestBody User user) {
......

}

它包含 id 和值 1 的原因是它必须在持久层自动生成。