컨트롤러에 JSON으로 전달하는 동적 이름/값 쌍이 있습니다.AJAX 게시 동적 JSON 개체 MVC 매핑
예 : 동적 JSON은 개체
{"vehicles":[{"odometer_675552753":"73750","odometer_723646452":"68127""price_709725300":"22984","price_709725299":"22999"}]}
var vehicleData = {
vehicles : []
};
var vehicles = {};
$('.firDataField').each(function() {
var id = $(this).attr("name");
var value = $(this).val();
vehicles[id]=value;
});
vehicleData.vehicles.push(vehicles);
$.ajax({
url: 'SaveVehicles.html',
contentType : 'application/json; charset=utf-8',
data:JSON.stringify(vehicleData),
type: "POST",
cache:false,
dataType : 'json',
success: function(data){
hideAjaxLoader();
},
error : function(jqxhr, textStatus, errorThrown) {
$('tbody#tbodyVehicleSearchData').html('');
hideLoading();
showGenericErrorMessage(jqxhr, textStatus, errorThrown, "VehicleSearch");
}
});
Controller:
@RequestMapping("/SaveVehicles.html")
public void
String saveVehicles(
@RequestParam(required = false, value = "vehicles") String jsonVehicleObject,
HttpServletRequest request, Model model)
throws Exception{
LOGGER.entry();
System.out.println("json: " + jsonVehicleObject);
}
jsonVehicleObject는 항상 null의 JQuery와
이하로 사용하여 생성. RequestBody를 Vehicle과 함께 객체 유형으로 사용해 보았습니다. 그러나 사용하지 마십시오. 어떤 제안?