Java Rest方法没有获得正确的数据
我有一个基本的SpringBoot应用程序。使用Spring初始值设定项、JPA、嵌入式Tomcat、Thymeleaf模板引擎,并将包作为可执行JAR文件。我已经定义了这个Rest方法来更新用户Java Rest方法没有获得正确的数据,java,rest,spring-boot,curl,restful-architecture,Java,Rest,Spring Boot,Curl,Restful Architecture,我有一个基本的SpringBoot应用程序。使用Spring初始值设定项、JPA、嵌入式Tomcat、Thymeleaf模板引擎,并将包作为可执行JAR文件。我已经定义了这个Rest方法来更新用户 @PutMapping(path = "/api/users/{id}", consumes = "application/json", produces = "application/json")
@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);
}
但是在System.out.printlnuser上;我从POJO获得的所有值都是null!?,但是缺少1@RequestBody注释的id
public ResponseEntity<User> updateUser
(HttpServletRequest request,
@PathVariable long id,
@RequestBody User user) {
......
}
它包含值为1的id的原因是它必须在持久层自动生成。您的用户类是什么样子的?此外,您应该在用户参数上添加@RequestBody注释,因为我认为Spring默认情况下需要一个请求参数。
public ResponseEntity<User> updateUser
(HttpServletRequest request,
@PathVariable long id,
@RequestBody User user) {
......