1. 程式人生 > >搭建ERP(分頁)

搭建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);
	}