ssm框架 使用ajax获取list集合,得到对象内容是空
jsp内容
$(function(){
$("#searchCustomer").click(function(){
$.post("${pageContext.request.contextPath}/customer/searchCustomer",$('#search').serialize(), function(data) {
alert(data);
console.log(data);
}, "json");
})
})
controller内容 得到的list集合,对象有内容
//搜索用户
@RequestMapping("searchCustomer")
@ResponseBody
public List<Customer> searchCustomer(Customer customer,Model model,HttpServletRequest request){
List<Customer> lists=new ArrayList<Customer>();
lists=customerService.searchCustomer(customer);
return lists;
}
得到

我已解决,是由于mybatis配置文件sql语句查询字段顺序不对,如果遇到可以用select xx as xx,xx as xx方式
前台的js能输出的列表对象是非空的,所以根源应该在Controller中返回list的地方,查询到的结果中。
断点打在return lists之前,看看searchCustomer的搜索结果是不是换化为列表的时候出错了。
后台输出内容可能转换json出错
alert(data);
console.log(data);打印出来是什么
你ajax设置的返回值为json,但后台返回的是list啊
spring视图中配置了fastjson等类似的转换吗