私はコントローラにJSONとして渡している動的な名前と値のペアを持っています。AJAXポスト動的JSONオブジェクトMVCマッピング
例:動的JSONオブジェクトはjsonVehicleObjectは常にnullである jQueryの
以下{"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);
}
を使用して生成されました。私はオブジェクトタイプとしてVehicleと共にRequestBodyを使用しようとしました。しかし、使用しないでください。助言がありますか?