我有控制器在哪里方法:
@RequestMapping(value = "carListForSelect", method = RequestMethod.GET,produces = "application/json")
public ResponseEntity<List<CarBD>> getCarListForSelect() {
List<CarBD> carList = carService.getAll();
HttpStatus httpStatus = carList != null ? HttpStatus.OK : HttpStatus.NOT_FOUND;
return new ResponseEntity<List<CarBD>>(carList, httpStatus);
}
此方法提供选择(我选择汽车的地方)
<div class="form-group">
<label for="carListSelect">Car name</label>
<select class="form-control" id="carListSelect">
</select>
$.ajax({
url:'car/carListForSelect',
type:'GET',
contentType: 'application/json;charset=UTF-8',
success: function( data ) {
$.each(data, function(i, value) {
$('#carListSelect').append($('<option></option>`').text(value.carName).attr('value',value));
});
}
});
如何从这个选择对象Car获取此JSON:
var exchange = {
"car": {
CAR OBJECT
},
"exchangeDate": $('#exchangeDateInput').val(),
"exchangePrice": $('#exchangePriceInput').val(),
"exchangeDescription": $('#exchangeDescriptionInput').val(),
};
};