0
Вот код на стороне клиента:JSON Ошибка в получении данных
function startAjax() {
$.ajax({
type : 'GET',
url : 'customers/ShowAllCustomers',//this is url mapping for controller
dataType: 'json',
contentType: 'application/json',
mimeType: 'application/json',
success : function(response) {
alert(response.get(0).first_name);
//this response is list of object commming from server
},
error : function() {
alert("opps error occured");
}
});
}
и вот мой контроллер:
@RequestMapping(value="/ShowAllCustomers", method = RequestMethod.GET)
public @ResponseBody List<Customer> AllCustomersList() {
List<Customer> customers= customerService.getAllCustomers();
return customers;
}
Everytime появляется предупреждение "упс ошибка". Не могли бы вы указать на ошибку в этом для меня. Я буду очень благодарна ......
ok. вы можете показать мне простой пример конверсии, пожалуйста? –
См. [This] (http://stackoverflow.com/questions/14228912/how-to-convert-list-to-json-in-java). – NINCOMPOOP
я изменил контроллером, его теперь выглядит следующим образом: @RequestMapping (значение = "/ ShowAllCustomers", метод = RequestMethod.GET) \t общественного @ResponseBody Строка AllCustomersList() { \t \t Список клиентов = customerService.getAllCustomers (); \t \t \t String json_customers = new Gson(). ToJson (клиенты); \t \t return json_customers; \t} , но все же не дает желаемых результатов; –