1、首先引入datagrid js ,css
$("#datagrid").bootstrap_datagrid({ url : "<%=path%>/user/findAllUser.html", params : { page : 1, pageSize : 10, name:name },singleSelect : true, pagination:true, columns : [ [ /* { title : "userid", field : "userid", hidden : true, }, */ { field : 'name', title : '用户名', }, { field : 'telephone', title : '外显号码', }, { field : 'shortphone', title : '手机号码', }, { field : 'createtime', title : '创建时间', }, { field : 'power', title : '联系人修改权限', width : 100, formatter:function(v,l){ if(v==0){ return '禁止修改'; } else if(v==1){ return '允许修改'; } } },{ title : "操作", formatter:function(v,l){ var c=''; c+=' '; return c; } } ] ] });
@RequestMapping("findAllUser") public void findAccount(HttpServletRequest req,HttpServletResponse res,int page,int pageSize,String name) throws Exception{ Domain domain = (Domain) req.getSession().getAttribute("Domainlogin"); Pagelist = userservice.findAllUser(domain.getDomainid(),name, page, pageSize); SimpleFilterProvider sfp = new SimpleFilterProvider(); sfp.addFilter("userFilter",SimpleBeanPropertyFilter.serializeAllExcept("rechargerecords")); String json = JacksonUtil.objToJson(list, sfp); writeString(json, res); }
@Override public PagefindAllUser(long domainid, String name,int page, int pageSize) { String hql=null; if(name==null){ hql="from Users u where u.domainid="+domainid; }else{ hql="from Users u where u.domainid="+domainid+" and lower(u.name) like '%"+name+"%'"; } Page page1 = new Page (); page1.setRows(dao.getEntityList(hql.toString()+" order by createtime desc", pageSize, page)); page1.setPage(page); page1.setTotalCount(dao.countByHql("select count(u.userid) " + hql)); return page1; }
2.用到的实体、封装的方法详见 百度云 http://pan.baidu.com/s/1dE8jNxB http://pan.baidu.com/s/1qYTIsCs