Hibernate高级查询方法

public List<BillMain> retrieve(BillMain billMain) {
		Criteria criteria = billMainDAO.getSession().createCriteria(
				BillMain.class);
		if (!StringUtil.isEmpty(billMain.getCustomerAdd())) {
			criteria.add(Restrictions.like("customerAdd", "%"
					+ billMain.getCustomerAdd().trim() + "%"));
		}
		// 根据公司名称查询
		/*
		 * if (!StringUtil.isEmpty(billMain.getCustomerName())) {
		 * criteria.add(Restrictions.like("customerName", "%" +
		 * billMain.getCustomerName().trim() + "%")); }
		 */
		if (!StringUtil.isEmpty(billMain.getEntryId())) {
			criteria.add(Restrictions.like("entryId", "%"
					+ billMain.getEntryId().trim() + "%"));
		}
		if (!StringUtil.isEmpty(billMain.getOperator())) {
			criteria.add(Restrictions.like("operator", "%"
					+ billMain.getOperator().trim() + "%"));
		}
		if (null != billMain.getOperaTime()) {
			criteria
					.add(Restrictions
							.sqlRestriction(" convert(varchar(10),this_.operaTime,120) like '%"
									+ billMain.getOperaTime().toString()
											.substring(0, 10) + "%'"));
		}
		criteria.add(Property.forName("state").eq("N")).addOrder(
				Order.desc("id"));

		return criteria.list();
	}

你可能感兴趣的:(java,Hibernate)