首页 > 代码库 > SQLQuery 实现别名映射
SQLQuery 实现别名映射
public List getQueryList(Map paramMap, int start, int maxResults) throws DataAccessException, HibernateException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { String woNo = ""; String woSubject = ""; Date creationDateFrom = null; Date creationDateEnd = null; if (paramMap.get("woNo") != null) { woNo = (String) paramMap.get("woNo"); } ; if (paramMap.get("woSubject") != null) { woSubject = (String) paramMap.get("woSubject"); } if (paramMap.get("creationDateFrom") != null) { creationDateFrom = (Date) paramMap.get("creationDateFrom"); } if (paramMap.get("creationDateEnd") != null) { creationDateEnd = (Date) paramMap.get("creationDateEnd"); } StringBuffer buf = new StringBuffer(); buf.append("select abh.*,"); buf.append("fw.wo_no bill_code,"); buf.append("fw.wo_type bill_type,"); buf.append("fw.wo_subject bill_title,"); buf.append("fw.created_date creation_date,"); buf.append("fw.process_instance_id process_instance_id,"); buf.append("‘transated‘ task_type,"); buf.append("(select au.user_name from arch_user au where au.user_id=abh.created_by) created_name,"); buf.append("(select ao.org_name from arch_org ao where ao.org_id=abh.arch_org_company_id) region_company_segment,"); buf.append("(select ao.org_name from arch_org ao where ao.org_id=abh.arch_org_dept_id) region_dept_segment"); buf.append(" from FAS_WORKORDER fw, ACCOUNT_BILL_HEAD abh where 1 = 1 "); buf.append(" and fw.businessid = abh.account_bill_head_id"); buf.append(" and fw.wo_no like :woNo"); buf.append(" and fw.wo_subject like :woSubject"); buf.append(" and fw.created_date between nvl(:creationDateFrom,fw.created_date) and nvl(:creationDateEnd,sysdate)"); buf.append(" order by fw.created_date desc"); List beanList = null; Session session = null; try { session = accountBillHeadDAO.getHibernateTemplate().getSessionFactory().openSession(); //获得本地sql查询对象 SQLQuery query = session.createSQLQuery(buf.toString()); //设置字符串参数 query.setString("woNo", "%" + woNo + "%"); query.setString("woSubject", "%" + woSubject + "%"); //设置日期参数 query.setDate("creationDateFrom", creationDateFrom); query.setDate("creationDateEnd", creationDateEnd); //设置分页 query.setFirstResult(start); query.setMaxResults(maxResults); query.setResultTransformer(new ExtColumnToBean(AccountBillHeadVOImpl.class)); beanList = query.list(); } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { session.flush(); session.close(); } return beanList; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。