搭建ERP(分页)

1、使用easyUI中DataGrid属性的pagination。设置为true,则会自动添加分页查询功能,但需要对业务层的代码做出相应的更改

                    pagination : true,

      备注: singleSelect : true设置为只能选中一行数据

	singleSelect : true

2、在spring的配置文件application.xml中设置多例模式

        <bean id="depAction" class="cn.itcast.erp.action.DepAction" scope="prototype">
		<property name="depBiz" ref="depBiz"></property>
	</bean>

3、需要自己设置总的记录数

//设置查询的聚合函数,总记录数
		dc.setProjection(Projections.rowCount());

4、在Action层需要将总记录属于放入map中

        public void getList() {
		int firstResult = (page-1)*rows;
		List<Dep> list = depBiz.getList(dep1,firstResult,rows);
		long total = depBiz.getCount(dep1);
		//网页传递的数据类型为{total:total,rows[]},所以需要将total和list放入map中
		Map<String,Object> mapData = new HashMap<>();
		mapData.put("total", total);
		mapData.put("rows", list);
		//把部门列表转JSON字符串
		String liststring = JSON.toJSONString(mapData);
		write(liststring);	
		}

5、查询优化,为以后增加条件查询坐准备。在条件查询的代码中增加Objec类,这样后期可以传递数组、集合等,增加dep2,这样当需要查询一个时间段的数据时,可以采用dep1和dep2中时间字段进行离线条件查询

/**
	 * 条件查询
	 */
	public List<Dep> getList(Dep dep1,Dep dep2,Object param,int firstResult,int maxResults) {
		DetachedCriteria dc = DetachedCriteria(dep1);
		return  (List<Dep>) this.getHibernateTemplate().findByCriteria(dc,firstResult,maxResults);
	}

猜你喜欢

转载自blog.csdn.net/xhudqlg/article/details/84310290
erp