extjs oracle分页---Json转换

由于ExtJs中很多地方用到json格式的数据,所以用json-lib很容易生成

分页的page类代码:

import java.util.List;

public class Page {

	private int totalCount;
	private List items;

	public Page(int totalCount, List items) {
		super();
		this.totalCount = totalCount;
		this.items = items;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List getItems() {
		return items;
	}

	public void setItems(List items) {
		this.items = items;
	}

}

 

 分页业务类代码:

	public Page deptPageQuery(int start, int limit, String sort, String dir) {
		// Oracle分页
		int star = start + 1;
		int end = start + limit;
		String sql = "select * from ( select rownum rnum, t.DEPTID,t.DEPTPID,t.DEPTNAME from LESDEPT t ) where rnum between "
				+ star + " and " + end;
		if (sort != null && !sort.equals("") && dir != null && !dir.equals("")) {
			sql += " order by " + sort + " " + dir;
		}
		Session session = null;
		List<SysDept> list = new ArrayList<SysDept>();
		Page page = null;
		try {
			session = HibernateSessionFactory.getSession();
			Query query = session.createSQLQuery(sql);
			list = query.list();
			page = new Page(list.size(), list);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			HibernateSessionFactory.closeSession();
		}
		return page;
	}

 

通过Json转换

Page page=dao.deptPageQuery(1, 3, "DEPTNAME", "desc");
JSONArray json=JSONArray.fromObject(page);
System.out.println(json.toString());

 

json所需jar如下:

 

  • jakarta commons-lang 2.4
  • jakarta commons-beanutils 1.7.0
  • jakarta commons-collections 3.2
  • jakarta commons-logging 1.1.1
  • ezmorph 1.0.6
  • json-lib-2.3-jdk15.jar
  •  

     

    你可能感兴趣的:(DAO,oracle,sql,json)