zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    Fluent动网格【8】:网格节点运动案例
    Fluent动网格【7】:网格节点运动
    Fluent动网格【6】:部件变形案例
    Fluent动网格【5】:部件变形
    Fluent动网格【4】:DEFINE_CG_MOTION宏实例
    Fluent动网格【3】:DEFINE_CG_MOTION宏
    Fluent动网格【1】:概述
    Fluent动网格【2】:Profile文件
    JavaScript系列--浅析原型链与继承
    简单说说JavaScript的Generator 实现(ES6)
  • 原文地址:https://www.cnblogs.com/rigid/p/3824469.html
Copyright © 2011-2022 走看看