后台从数据库获取数据后,解析成json文件
这里需要额外导入ObjectMapper的依赖包
利用mapper来解析传入的数据
private void query(HttpServletResponse response){
try {
List<ExamMessage> list = examService.query();
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", list.size());
map.put("rows", list);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(map);
response.setCharacterEncoding("utf-8");//防止在界面出现乱码,地址加载不出来。
PrintWriter out = response.getWriter();
out.append(json.toString());
out.flush();
out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(file_D);
}
前端界面代码(获取json数据后处理)
部分代码参考js文档和easyUI文档
$(function(){
$('#dg').datagrid({
//url:'datagrid-data.json',
url:'examServlet',
//url:'userServlet',
fit:true,
striped:true,
pagination:true,
rownumbers:true,
singleSelect:false,
toolbar: '#tb',
//easyUI数据网格那一块查询以下数据
rowStyler: function(index,row){
if (row.unitcost>80){
return 'background-color:#6293BB;color:#fff;'; // return inline style
// the function can return predefined css class and inline style
// return {class:'r1', style:{'color:#fff'}};
}
//对一些特殊的数据进行标记的作用
},
columns:[[
{checkbox:true,field:''},
//checkbox是复选框,可以单个选择
{field:'id',title:'编号',width:100},
{field:'college',title:'学院',width:100,editor:'textbox'},
{field:'classRoom',title:'教室',width:100,editor:'textbox'},
{field:'totalStuNum',title:'教师容量',width:100,editor:'textbox'},
{field:'studentNum',title:'考生人数',width:100,editor:'textbox'},
{field:'campus',title:'校区',width:100,editor:'textbox'},
{field:'iscomRoom',title:'是否机房',width:100,editor:'textbox'},
]]
});
$('#dg').datagrid({
onDblClickRow:function(rowIndex, rowData){
//alert(rowIndex+" "+rowData.username)
//$("#dg").datagrid("beginEdit",rowIndex);
}
});
update_it=1;
});
henu_student
发布了11 篇原创文章 · 获赞 3 · 访问量 78
私信
关注