0
我旁邊Ajax請求AJAX POST 415(不支持的媒體類型)
$.ajax({
contentType: 'application/json',
mimeType: 'application/json',
type: frm.attr('method'),
url: frm.attr('action'),
dataType: 'json',
data: JSON.stringify(data),
success: function (response) {
alert("success" + response);
},
error: function (jqXHR) {
var errorMessage = $(jqXHR.responseText).filter('p:eq(1)').find('u').text();
alert("error " + errorMessage);
}
});
,我發送了一封信實體
@Entity
@Table(name = "LETTERS")
public class Letter {
@Id
@Column(name = "ID")
@GeneratedValue
private long id;
@Column(name = "MESSAGE")
private String message;
@Column(name = "EMAIL")
private String email;
@Column(name = "CREATING_DATE")
private Date creatingDate;
@Column(name = "DELIVERY_DATE")
private Date deliveringDate;
public Letter() {
}
//... getters and setters
}
,並在我的控制,我不能讓這個實體的原因不支持媒體類型
@RequestMapping(value = "/main", method = RequestMethod.POST)
@ResponseBody
public void addLetterToDB(@RequestBody Letter letter) {
System.out.println(letter);
}
但是,如果我在方法簽名字母類型更改爲字符串類型它將起作用,但我想採取實體)請求幫助。
找到的答案只是添加依賴新春版本4.1.7 http://stackoverflow.com/questions/7462202/spring-json-request-getting-406-not-acceptable – jenius