0
我想将数据库中的所有数据作为json array
发送给jsp以由ajax提取。将json对象从控制器返回给jsp
EmployeeController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@RequestMapping(value = "/index", method = RequestMethod.GET)
public @ResponseBody List<Employee> listAllUsers() {
return employeeService.listEmployeess();
}
和JSP
ajaxCall = function() {
$.ajax({
url : 'EmployeeController',
type : 'GET',
dataType : 'json',
error : function(that, e) {
alert(e);
},
success : function(data) {
alert(data);
}
});
}
因此如何使这个?
当你调用'employeeService.listEmployeess()'时返回什么? –
使用Gson库和'.toGson(Your_Object)'方法将你的Java对象转换成json数组。或者使用'jackson'库,它将把你的响应作为json数组返回。 –