Dao层查询

得到list的几种方式:

一:继承HibernateDaoSupport类

1,this.getSession().createQuery(hql.toString()).list();

@SuppressWarnings("unchecked")
	public List<BusinessOrderRelation> getBrList(String orderNo,Integer orderSubNo,String type,String fdbs,String seqNo)
	{
		StringBuffer hql = new StringBuffer();
		List<BusinessOrderRelation> list = new ArrayList<BusinessOrderRelation>();
		hql.append("from BusinessRelation bor  where 1=1 ");
		hql.append(" and bor.orderNo =:orderNo and bor.orderSubNo = :orderSubNo ")
		          .append("and bor.type = :type and bor.fdbs = :fdbs and seqNo like '")
                       .append(seqNo)
                          .append("%') ))");
		list = this.getSession().createQuery(hql.toString())
						.setString("orderNo", orderNo)
						.setInteger("orderSubNo", orderSubNo)
						.setString("type", type)
						.setString("fdbs", fdbs)
						.list();
		return list;
	}

 2,this.getHibernateTemplate().find(hql.toString());

@SuppressWarnings("unchecked")
	public List<Pscrkkphz> findDbPsrkkpInfor(String fdbs,String djbs) throws DataAccessFailureException
	{
		StringBuffer hql = new StringBuffer();	
		hql.append("from Pscrkkphz where 1=1 and djbs = '"+ djbs +"' and executeStatus = 'N'");
		if(!UtilHelper.isEmpty(fdbs))
		{
			hql.append(" and fdbs = '")
			.append(fdbs).append("'");
		}
		return this.getHibernateTemplate().find(hql.toString());
	}

二:继承JdbcDaoSupport类

1,this.getJdbcTemplate().query(sql.toString(), ParameterizedBeanPropertyRowMapper.newInstance(CaogaomxDto.class), new Object[]{djbh});

public List<CaogaomxDto> findCaogaomxInfor(String djbh) throws DataAccessFailureException{
		StringBuffer sql = new StringBuffer();
		sql.append("select cm.*, dor.draft_order_relation_id, dor.order_no, dor.order_sub_no, dor.original_order_no, "); 
		sql.append("dor.original_order_sub_no, dor.original_not_arrival_quantity notArrivalQuantity from caogaomx cm ");
		sql.append(" left join draft_order_relation dor on cm.plh = dor.order_no  and cm.dj_sn = dor.order_sub_no where 1 = 1 ");
		if(!UtilHelper.isEmpty(djbh)){
			sql.append(" and cm.plh = ? ");
		}
		return this.getJdbcTemplate()
			.query(sql.toString(), ParameterizedBeanPropertyRowMapper.newInstance(CaogaomxDto.class), new Object[]{djbh});
	}

2,this.getJdbcTemplate().queryForList(sql.toString(), new Object[]{originalOrderNo, originalOrderSubNo});

	public List<Map<String, Object>> getConfirmJeAndHsjeByOriginalOrder(
			String originalOrderNo, Integer originalOrderSubNo)
			throws DataAccessFailureException {
		StringBuffer sql = new StringBuffer();
		sql.append("select cx.je, cx.hsje, cx.shl, cx.hshj from Confirmmx cx where 1 = 1 ");
		if(!UtilHelper.isEmpty(originalOrderNo)){
			sql.append("and cx.original_Order_No = ? ");
		}
		if(!UtilHelper.isEmpty(originalOrderSubNo)){
			sql.append("and cx.original_Order_Sub_No = ? ");
		}
		sql.append("and cx.EXECUTE_STATUS = '").append(McConstants.CONFIMR_ORDER_PASS).append("'");
		return this.getJdbcTemplate().queryForList(sql.toString(), new Object[]{originalOrderNo, originalOrderSubNo});
	}
原文地址:https://www.cnblogs.com/csuwangwei/p/2281692.html