您好我在尝试访问端点时收到400错误请求。我使用spring mvc并将我的url映射到我的页面,但在使用window.location.href
时无法访问端点。请问我做错了什么
以下是我的代码:
$.ajax({
type: 'post',
url: 'guest/search',
data: JSON.stringify(formData),
contentType: 'application/json',
success: function(dataRecieved){
var dataRecieved= $.trim(dataRecieved);
//console.log(dataRecieved);
if(dataRecieved === 'true'){
$("#statusPlaceholder").html("Great rooms are available");
window.location.href="/guestReservation"; //fails to go to the endpoint
}else{
$("#statusPlaceholder").html("Sorry. Rooms are not available. Please try again").show().fadeOut(3000).css("color","red");
}
}
});
我映射的终点:
@RequestMapping(value = "/guestReservation", method = RequestMethod.GET)
public
@ResponseBody
String createGuest(@RequestBody Occupancy occupancy){
return "guestReservation";
}
这是我的入学课程:
@Entity
@Table(name="Occupancy")
public class Occupancy implements Serializable {
private static final long serialVersionUID = 15L;
public Occupancy() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="OCCUPANCYID", nullable = false)
private long occupancyID;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="itinaryID")
private Itinary itinary;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "roomNumber", referencedColumnName = "roomID")
private Room room;
@Column(name="roomsWanted")
private int roomsWanted;
public int getRoomsWanted() {
return roomsWanted;
}
public void setRoomsWanted(int roomsWanted) {
this.roomsWanted = roomsWanted;
}
// @Column(name="status", columnDefinition = "default 0")
private int status; // 0:reserved 1:cheched-in 2:checked-out
private Date checkInDate;
private Date checkOutDate;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public long getOccupancyID() {
return occupancyID;
}
public Itinary getItinary() {
return itinary;
}
public void setItinary(Itinary itinary) {
this.itinary = itinary;
}
public Room getRoom() {
return room;
}
public void setRoom(Room room) {
this.room = room;
}
// public int getNunOfPerson() {
// return NunOfPerson;
// }
//
// public void setNunOfPerson(int nunOfPerson) {
// NunOfPerson = nunOfPerson;
// }
public Date getCheckInDate() {
return checkInDate;
}
public void setCheckInDate(Date checkInDate) {
this.checkInDate = checkInDate;
}
public Date getCheckOutDate() {
return checkOutDate;
}
public void setCheckOutDate(Date checkOutDate) {
this.checkOutDate = checkOutDate;
}
}
答案 0 :(得分:0)
我认为问题是因为/ guestReservation API调用中预期的参数。
我在方法定义中看到,参数的类型为 Guest 。您需要检查本课程中您期望的内容。
添加所需参数可以解决您的问题。
希望它有所帮助!