服务器端读取数据库 返回list 然后将list打包成json
public String loadModel() throws DataBaseException, IOException{
HttpServletRequest request=ServletActionContext.getRequest();
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("application/x-javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
String brandId = request.getParameter("brandId");
List phones = this.phoneService.queryMobilByBrandId(Integer.parseInt(brandId));
if(phones!=null&&phones.size()>0){
//把集合对象转换为json对象
JSONArray json=JSONArray.fromObject(phones);
out.println(json.toString());
out.close();
}else{
out.println("[{id:0,model:'请选择'}]");
out.close();
}
return SUCCESS;
}