내가 뭘 잘못 했습니까? 나는 봄 mvc와 JSON을 사용하려고한다. 내 코드를 디버깅하려고 할 때 자바 스크립트가 작동하지만 컨트롤러가 작동하지 않습니다. 브라우저에서 415 Unsupported Media Type 오류가 발생합니다.JSON plus spring mvc 3.2 오류 415 (지원되지 않는 미디어 유형)
스크립트 :
$(document).ready(function() {
$('#newSmartphoneForm').submit(function(event) {
var producer = $('#producer').val();
var model = $('#model').val();
var price = $('#price').val();
var json = { "producer" : producer, "model" : model, "price": price};
$.ajax({
url: $("#newSmartphoneForm").attr("action"),
data: JSON.stringify(json),
type: "POST",
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
},
success: function(smartphone) {
var respContent = "";
respContent += "<span class='success'>Smartphone was created: [";
respContent += smartphone.producer + " : ";
respContent += smartphone.model + " : " ;
respContent += smartphone.price + "]</span>";
$("#sPhoneFromResponse").html(respContent);
}
});
event.preventDefault();
});
});
컨트롤러 :
@RequestMapping(value="/create", method=RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Smartphone createSmartphone(@RequestBody Smartphone smartphone) {
return smartphoneService.create(smartphone);
}
사용중인 Spring MVC 버전은 무엇입니까? 네트워크 콘솔을여십시오. 'Content-Type' 헤더를 보셨습니까? 우리에게'스마트 폰'수업을 보여주세요. –