smartclient 分頁 及 不能正常分頁解析

Smartclient 分頁

詳細閱讀AIP 可以知道paging兩個參數 分別是:endRow 、startRow、
後臺響應客戶端請求時,遵循客戶端接收參數的方式,(response /data)

listGrid dataPageSize:75默認值為75,在listgrid中一次顯示75條記錄 第一次請求中 startrow 0 endrow 75 當鼠標往下拉動,記錄數達到75條,客戶端會自動發送請求至服務器,startrow 75 endrow 150,後臺接收參數進一步處理。。and so on。。

剛開始摸索分頁功能的時候 真的是從頭到尾的把代碼懷疑了一遍 *_* 後來還

是沒出來,總感覺就差哪裡一點點沒配置好,就感覺馬上出來了。(*^__^*) 過了n久 ,終於慢悠悠的做出來了,總是這樣滴,做出來之後才覺得,簡單。。。
辛苦了。
	/*
	 * 从数据库中提取数据 以json格式存储
	 * 
	 * 以json格式将记录集返回
	 * 
	 * */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="demoApp/findAll.action")
	public @ResponseBody Map<String,Object> findSupplyItemForPage(HttpServletResponse response,HttpServletRequest request){
		   String category = request.getParameter("category");//接受前台传过来的参数
	       String start = request.getParameter("_startRow");
	       String  end = request.getParameter("_endRow");
	       
	        int firstResult = 0 ;
	        int maxResults = 75 ;
	        List<supplyItem> list = null;
	        Map<String, Object> map = new HashMap<String, Object>();
	        Map<String, Object>mapreturn = new HashMap<String,Object>();
	        
	        if ((null != start) && ("" != start)) {
	            firstResult = Integer.parseInt(start);
System.out.println("----- firstResult: " + firstResult + " -----");	         
	        }
	        if ((null != end) && ("" != end)) {
	            maxResults = Integer.parseInt(end);
System.out.println("----- maxResults: " + maxResults + " -----");
	        }

	        List<supplyItem> totalRows = this.supplyItem_service.totalRows(category);
System.out.println("打印總記錄數totals------->" + totalRows.get(0) + "條");

	        //判断category是否为null 若为null则查询所有记录 否则返回指定记录
	        if (category == null) {
	            list = this.supplyItem_service.findInfo();
	        } else {
	               list = this.supplyItem_service.findSupplyItemForPage(category, firstResult, maxResults);
	        }
	        map.put("endRow", maxResults);
	        map.put("queueStatus", 0);
	        map.put("totalRows", totalRows.get(0));
	        map.put("isDSResponse", true);
	        map.put("invalidateCache", false);
	        map.put("status", 0);
	        map.put("startRow", firstResult);
	        map.put("data", list);
	        mapreturn.put("response", map);
	        return mapreturn;
	}
返回值份兩層 response 和data 

前臺設置restDataSource recordXPath: response/data
isc.RestDataSource.create({ 
   	    ID:"supplyItem",
	    dataFormat:"json",  //数据格式 xml格式
	    recordXPath:"response/data", //--<country></country> 
	    fields:[
	        {name:"itemID",title:"itemID",primaryKey:true},//countryCode設置為主鍵
	        {name:"itemName", title:"itemName"},
	        {name:"unitCost", title:"unitCost"},
	        {name:"sku",title:"sku"},
	        {name:"description",title:"description"},
	        {name:"category",title:"category"},
	        {name:"inStock",title:"inStock"},
	        {name:"nextShipment",title:"nextShipment"}
	    ],
	    
	    operationBindings:[ 
	        {operationType:"fetch", dataURL:"demoApp/findAll.action" },
	        {operationType:"add", dataURL:"demoApp/insertInfo.action"},
	        {operationType:"update",  dataURL:"demoApp/updateInfo.action" },
	        {operationType:"remove", dataURL:"demoApp/deleteInfo.action" }
	    ]
	});

Dao 層 分頁sql
   public List<supplyItem> findSupplyItemForPage(final String category,

	          final int firstResult, final int maxResults) {

		   return this.hibernateTemplate.executeFind(new HibernateCallback() {

	            public Object doInHibernate(Session session)

	            throws HibernateException, SQLException {

	                return session.createQuery("from supplyItem where category='" + category + "'")

	                .setFirstResult(firstResult).setMaxResults(maxResults).list();
	            }

	        });

	    }






你可能感兴趣的:(json,String,object,list,session,null)