스프링 포틀릿 MVC에서 @ResourceMapping의 JSON 매개 변수를 어떻게 interprete 할 수 있는지 검색하고 있습니다. @RequestBody를 추가하면 다음 메시지가 나타납니다. @RequestBody는 지원되지 않습니다.Ajax 요청에서 JSON을 받아들이는 @ResourceMapping
보기 측 :
<portlet:resourceURL var="getTest" id="ajaxTest" ></portlet:resourceURL>
<p>
<button onClick="executeAjaxTest();">Klik mij!</button>
<button onClick="$('#ajaxResponse').html('');">Klik mij!</button>
</p>
<p>
<h3>Hieronder het antwoord:</h3>
<h4 id="ajaxResponse"></h4>
</p>
<script>
function executeAjaxTest() {
var jsonObj = {
user: "Korneel",
password: "testpassword",
type: {
testParam: "test",
}
}
console.debug(JSON.stringify(jsonObj));
$.ajax({
dataType: "json",
contentType:"application/json",
mimeType: 'application/json',
url:"<%=getTest%>",
data:JSON.stringify(jsonObj),
success : function(data) {
$("#ajaxResponse").html(data['testString']);
}
});
}
</script>
컨트롤러 측 :
내가 이것을 가지고가 어떻게 내 자신의 모델에 자동으로 맵이 JSON 데이터를 봄 마법을 사용할 수 있습니다
@ResourceMapping(value="ajaxTest")
@ResponseBody
public void ajaxTestMethod(ResourceRequest request, ResourceResponse response) throws IOException, ParseException {
LOGGER.debug("ajax method");
JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("testString", "Ik ben succesvol verstuurd geweest!");
response.getWriter().write(json.toString());
}
? 참고 : Spring MVC가 아닌 Spring 포틀릿 MVC입니다.