jsp页面
js代码:
$(function() {
$('#ff').hide();
$('#tt').datagrid({
title : '信息显示',
iconCls : 'icon-save',
width : 'auto',
height : 'auto',
pageSize:10,
pageList : [ 5, 10, 15 ],
nowrap : true,
striped : true,
collapsible : true,
url : 'pecc/peccList.action',
loadMsg : '数据装载中......',
onLoadError : function() {
alert('数据加载失败!');
},
sortName : 'code',
sortOrder : 'desc',
remoteSort : false,
frozenColumns : [ [ {
field : 'ck',
checkbox : true
} ] ],
columns : [ [ {
title : '车牌号',
field : 'carNumber',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '车主',
field : 'carPer',
width : '100',
rowspan : 2,
align : 'center'
}, {
title : '违章时间',
field : 'pTime',
width : '80',
rowspan : 2,
align : 'center'
}, {
title : '违章地点',
field : 'pPlace',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '违章原因',
field : 'pCase',
width : '220',
rowspan : 2,
align : 'center'
}, {
title : '来源',
field : 'pOrg',
width : '120',
rowspan : 2,
align : 'center'
}, {
title : '交警大队',
field : 'pPer',
width : '300',
rowspan : 2,
align : 'center'
} ] ],
pagination : true,
rownumbers : true,
toolbar : [ {
text : '全部',
iconCls : 'icon-ok',
handler : function() {
$('#tt').datagrid({
url : 'pecc/peccList.action'
});
}
}, '-', {
text : '添加',
iconCls : 'icon-add',
handler : function() {
openAdd();
$('#ff').show();
$('#ff').form('clear');
$('#ff').appendTo('#aa');
}
}, '-', {
text : '修改',
iconCls : 'icon-edit',
handler : getSelect
}, '-', {
text : '删除',
iconCls : 'icon-remove',
handler : del
}, '-', {
text : '查询',
iconCls : 'icon-search',
handler : function() {
$('#query').window('open');
}
} ]
});
displayMsg();
});
function displayMsg() {
$('#tt').datagrid('getPager').pagination({
displayMsg : '当前显示从{from}到{to}共{total}记录'
});
}
Action 代码:
@Controller
@ParentPackage("mydefault")
@Namespace("")
public class Pecc extends ActionSupport {
private static final long serialVersionUID = 1L;
@Resource
PerinfoService perinfoService;
@Resource
PeccancyService peccancyService;
@Action("/pecc")
public String peccList() {
try {
HttpServletRequest re = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
JSONArray jsonArray = new JSONArray();
JSONObject jsonobj = new JSONObject();
Map<String, Object> map = new HashMap<String, Object>();
long all = perinfoService.getCount(map);
String page = re.getParameter("page");
String rows = re.getParameter("rows");
// 当前页
int intPage = Integer.parseInt((page == null || page == "0") ? "1" : page);
// 每页显示条数
int number = Integer.parseInt((rows == null || rows == "0") ? "10" : rows);
// 每页的开始记录 第一页为1 第二页为number +1
int start = (intPage - 1) * number;
map.put("page", start);
map.put("pageCount", number);
List<Peccancy> list = peccancyService.getList(map);
for (Peccancy con : list) {
jsonobj.put("id", con.getId());
jsonobj.put("carNumber", con.getCarNumber());
jsonobj.put("carPer", con.getCarPer());
jsonobj.put("pTime", sdf.format(con.getPTime()));
jsonobj.put("pPlace", con.getPPlace());
jsonobj.put("pCase", con.getPCase());
jsonobj.put("pOrg", con.getPOrg());
jsonobj.put("pPer", con.getPPer());
jsonArray.add(jsonobj);
}
Map<String, Object> json = new HashMap<String, Object>();
json.put("total", all);// total键 存放总记录数,必须的
json.put("rows", jsonArray);// rows键 存放每页记录 list
jsonobj = JSONObject.fromObject(json);// 格式化result一定要是JSONObject
out.print(jsonobj);
out.flush();
out.close();
} catch (IOException e) {
System.out.println(e);
}
return null;
}
Struts.xml 配置:
<package name="mydefault" extends="struts-default">
<global-results>
<result name="exception">/index.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="exception" />
</global-exception-mappings>
</package>