通过postman raw json主体传递新对象将给出空值

t30tvxxf  于 2022-11-07  发布在  Postman
关注(0)|答案(1)|浏览(318)

我试图通过postman使用raw body json发布一个新对象(Nuser)。生日和插入都通过了,但是名字和姓氏都是空值。我自己似乎找不到这个问题,所以我在这里问它。

我的基本用户类:

@Entity
public abstract class BaseUser {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int Id;

    private String FirstName;

    private String LastName;
    private String Insertion;
    private LocalDate Birthdate;

    public BaseUser() {
    }

    public BaseUser(String firstName, String lastName, String insertion, LocalDate birthdate) {
        FirstName = firstName;
        LastName = lastName;
        Insertion = insertion;
        Birthdate = birthdate;
    }

    public BaseUser(int id, String firstName, String lastName, String insertion, LocalDate birthdate) {
        Id = id;
        FirstName = firstName;
        LastName = lastName;
        Insertion = insertion;
        Birthdate = birthdate;
    }

我的Nuser类

@Entity
public class Nuser extends BaseUser
{
    public Nuser(String firstName, String lastName, String insertion, LocalDate birthdate) {
        super(firstName, lastName, insertion, birthdate);
    }

    public Nuser() {

    }
}

Nuser控制器

@RestController
@RequestMapping("/user")
public class NuserController {

    @Autowired
    private NuserService nuserService;

    @PostMapping("/add")
    public String add(@RequestBody Nuser nuser)
    {
        nuserService.AddUser(nuser);
        return "New account has been made";
    }

}
rwqw0loc

rwqw0loc1#

firstnamefirstNameFirstName都是不同的标识符。它们需要匹配。
请注意,以下Java约定将使您的工作变得更加轻松:不是类的项(变量、字段、方法)的名称应以小写字母开头。此外,以下 REST 约定将使您的工作更轻松:POST已经意味着“添加”,所以在URL中不要有额外的/add,只要POST /user

相关问题