Springboot接收前端的Json但是为null

接收前端传过来的Json,

{
    "id": 94,
    "nickname": "王明",
    "username": "萧强",
    "password": "nulla",
    "email": "[email protected]",
    "avatar": "http://dummyimage.com/100x100",
    "type": 47,
    "createTime": "2007-12-03 08:23:55",
    "updateTime": "1972-02-26 05:02:56"
}


然后反序列化转化成User实体类,打印实体类为空,仔细检查了一下。

    @PostMapping(value = "/register")
    public Result registerUser(User user) {
        userService.register(user);
        return ResultGenerator.getSuccessResult(user);
    }

少了@RequestBody注解

    @PostMapping(value = "/register")
    public Result registerUser(@RequestBody User user) {
        userService.register(user);
        return ResultGenerator.getSuccessResult(user);
    }

现在实体类就有数据了。

你可能感兴趣的:(SpringBoot,spring,boot,json,java)