Home > Net >  bad request in spring boot
bad request in spring boot

Time:07-08

i am new to spring and i created simple end point to get and create students. i have this get mapping method to register new students

@PostMapping
    public void registerNewStudent(@RequestBody Student student){
        studentService.addNewStudent(student);
    }

and this is my student class


@Entity
@Table
public class Student {
    @Id
    @SequenceGenerator(
            name = "student_sequence",
            sequenceName = "student_sequence",
            allocationSize = 1
    )
    @GeneratedValue(
            strategy = GenerationType.SEQUENCE,
            generator = "student_sequence"
    )
    private long id;
    private String name;
    private String email;
    private LocalDate dob;
    @Transient
    private Integer age;

    public Student() {
    }

    public Student(String name, String email, LocalDate dob) {
        this.name = name;
        this.email = email;
        this.dob = dob;
    }



        @Override
    public String toString() {
        return "Student{"  
                "id="   id  
                ", name='"   name   '\''  
                ", email='"   email   '\''  
                ", dob="   dob  
                ", age="   age  
                '}';
    }
}

but when i test it in postman i get the error 400 for bad request enter image description here any idea please ?

CodePudding user response:

Assuming that the URL you are trying to access maps properly.

Annotate dob field with below annotation.

@Column(columnDefinition = "DATE")

Also update the postman request date with "1999-03-01"

  • Related