關於怎麼解決從ajax傳入的json引數注入到Controller的接收物件 以及如何在Spring Boot專案使用引數校驗
<html>
<head>
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" >
<title>Insert title here</title>
<script type= "text/javascript"
src= "<%=basePath%>resources/scripts/jquery-2.0.3.min.js" ></script>
<script type= "text/javascript" >
$( function (){
$( "#send" ).click( function (){
var jsondata = $( "#jsondata" ).val();
var jsonobj = JSON.parse(jsondata)
var callback = function (data) {
$( "#result" ).html(JSON.stringify(data))
}
$.postJSON( '<%=basePath%>api/user/test' , jsonobj, callback) });
})
$.postJSON = function (url, data, callback) {
return jQuery.ajax({
'type' : 'POST' ,
'url' : url,
'contentType' : 'application/json' ,
'data' : JSON.stringify(data),
'dataType' : 'json' ,
'success' : callback
});
};
</script>
</head>
<body> JSON物件
<br>
<textarea id= "jsondata" cols= "60"
|