AngularJS帖子数据显示"The request sent by the client was syntactically incorrect"



Angular post request

                $http({
                      method: 'POST',
                      url: '/Eatery/save',
                      contentType:'application/json',
                      dataType:'json',
                      data:JSON.stringify(resvnCtrl.user)
                });
<<p> 预约模型/strong>
@Entity
@Table(name="reservations")
public class Reservation implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = -2657656545798031761L;
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    private String cnf;
    private String name;
    private String email;
    private String phone;
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    private LocalDateTime time;
    private int seats;
    private String note;
    public Reservation() { }
    public Reservation(String cnf, String name, String email, String phone,
            LocalDateTime time, int seats, String note) {
        this.cnf = cnf;
        this.name = name;
        this.email = email;
        this.phone = phone;
        this.time = time;
        this.seats = seats;
        this.note = note;
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getCnf() {
        return cnf;
    }
    public void setCnf(String cnf) {
        this.cnf = cnf;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    @JsonSerialize(using=CustomDateSerializer.class)
    public LocalDateTime getTime() {
        return time;
    }
    public void setTime(LocalDateTime time) {
        this.time = time;
    }
    public int getSeats() {
        return seats;
    }
    public void setSeats(int seats) {
        this.seats = seats;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
}
<<p> 春控制器/strong>
@RequestMapping(value="/save",method=RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public int save(@RequestBody Reservation reservation) {
        System.out.println(reservation.getTime());
        return reservationRepo.save(reservation);   
    }

我有一个angular post请求,它发送JSON数据和一个处理该请求的spring控制器。当我尝试这个我得到了错误客户端发送的请求在语法上是不正确的。前端的数据来自一个表单。我使用引导日期选择器进行日期选择。谁能指出我的错误

无需对数据对象进行字符串化。

            $http({
                  method: 'POST',
                  url: '/Eatery/save',
                  contentType:'application/json',
                  dataType:'json',
                  data:resvnCtrl.user
            });

相关内容

最新更新