java 代码
- /**
- * 多表分页,然后影射成JAVABEAN
- * @param sqlcount HSQL计算多表查询的总数
- * @param sqllist HSQL多表查询的语句
- * @return List
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- * @throws InstantiationException
- * @throws IllegalArgumentException
- * @throws ClassNotFoundException
- * @throws NoSuchMethodException
- * @throws SecurityException
- * @throws DaoException
- */
- public List mutiTableList(String sqlcount,String sqllist,String classname,Class partypes[]) throws DataAccessException, HibernateException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, SecurityException, NoSuchMethodException {
- HttpServletRequest httpRequest = BaseAction.getHttpRequest();
- System.out.println("执行次数"+(count++));
- List res = new ArrayList();//将用于存放保存的结果集合
- org.hibernate.ScrollableResults srs = null;
- Session session = this.getSession();
- int total = queryTotalCount(sqlcount);
- records.setTotalNum(total);
- // records.setParam(condition);
- String pageSize = RequestUtil.getParam(httpRequest, "pageSize", String.valueOf(PagedList.DEFAULT_PAGE_SIZE));
- records.setPageSize(Integer.parseInt(pageSize));
- int totalPage = records.getTotalPage();
- RequestUtil.setParam(httpRequest, "pageSize", pageSize);
- // 用自定义的辅助类来取参数值,如果参数为空,则返回指定的默认值
- String page = RequestUtil.getParam(httpRequest, "page", "1");
- if (Integer.parseInt(page) > totalPage) {
- page = "" + totalPage;
- }
- // 设置请求页码
- records.setPage(Integer.parseInt(page));
- //下面创建一个匿名Query实例并调用它的scroll()方法返回以ScrollableResults形式组织的查询结果
- Query q = session.createQuery(sqllist);
- q.setFirstResult(records.getQueryStartNum()-1);
- q.setMaxResults(records.getQueryEndNum());
- srs = q.scroll();
- //将查询结果放入List保存
- while(srs.next()){
- Class cl=Class.forName(classname);
- Constructor cs = cl.getConstructor(partypes);
- Object ob[]=new Object[partypes.length];
- for(int i=0;i
- if (partypes[i] == String.class){
- ob[i]=srs.getString(i);
- }
- else if (partypes[i] ==int.class){
- ob[i]=srs.getInteger(i);
- }
- else if (partypes[i] ==long.class){
- ob[i]=srs.getLong(i);
- }
- else if (partypes[i] ==short.class){
- ob[i]=srs.getShort(i);
- }
- else if (partypes[i] ==float.class){
- ob[i]=srs.getFloat(i);
- }
- else if (partypes[i] ==double.class){
- ob[i]=srs.getDouble(i);
- }
- else if (partypes[i] ==byte.class){
- ob[i]=srs.getDouble(i);
- }
- else if (partypes[i] ==char.class){
- ob[i]=srs.getDouble(i);
- }
- else if (partypes[i] ==boolean.class){
- ob[i]=srs.getDouble(i);
- }
- else if (partypes[i] ==Date.class){
- ob[i]=srs.getDate(i);
- }
- }
- Object ob2 =cs.newInstance(ob);
- res.add(ob2);
- }
- records.setStart(records.getQueryStartNum());
- records.setSource(res);
- String url = httpRequest.getRequestURI();
- String query = CharUtil.IsoToGbk(httpRequest.getQueryString());
- records.setRequestURL(url + RequestUtil.getParamQueryString(query));
- //设置分页参数
- httpRequest.setAttribute("records", records);
- return records.getList();
- }
java 代码
- /**
- *调用方法
- *
- */
- public List listTable1()throws DataAccessException, HibernateException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
- String sqlcount="select count(*) from Table1 t, Cclq c where c.ringname=t.name";
- String sqllist="select t.id,t.name,c.ringname from Table1 t, Cclq c where c.ringname=t.name";
- String classname="com.prpsdc.infosystem.model.Test";
- Class partypes[]=new Class[]{int.class,String.class,String.class};
- return mutiTableList(sqlcount,sqllist,classname,partypes);
- }
java 代码
- /**
- *此类必须有明确的构造函数,如下,mutitablelist方法将通过反射机制将结果映射为此JAVABEAN,以*ArrayList保存.HIbernate的查询结果就是本JAVABEAN的集合.此类无须配置*.HBM.XML
- *public Test(int id,String name,String ringname){ }
- */
- package com.prpsdc.infosystem.model;
- public class Test {
- public Test(int id,String name,String ringname){
- this.id=id;
- this.name=name;
- this.ringname=ringname;
- }
- public int id;
- public String name;
- public String ringname;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getRingname() {
- return ringname;
- }
- public void setRingname(String ringname) {
- this.ringname = ringname;
- }
- }
- *