Пример #1
0
  @Override
  public Long countCustomersByCondition(Customers customers) {
    String strHql = "SELECT COUNT(e.CUSTOMER_ALL_ID) FROM T_CUSTOMER_ALL e WHERE 1=1";
    // 类型的模糊查询
    if (null != customers.getState() && !"".equals(customers.getState().toString().trim())) {
      strHql +=
          " and e.CUSTOMER_ALL_STATE LIKE('%" + customers.getState().toString().trim() + "%')";
    }
    // 客户名称的模糊查询
    if (null != customers.getCname() && !"".equals(customers.getCname().trim())) {
      strHql += " and e.CUSTOMER_ALL_CNAME LIKE('%" + customers.getCname().trim() + "%')";
    }

    Query query = entityManager.createNativeQuery(strHql);
    return Long.parseLong(query.getSingleResult().toString());
  }
Пример #2
0
 @Override
 public List<Customers> findCustomersByCondition(
     Customers customers, Integer start, Integer limit) {
   String strHql = "SELECT e.* FROM T_CUSTOMER_ALL e WHERE 1=1";
   // 类型的模糊查询
   if (null != customers.getState() && !"".equals(customers.getState().toString().trim())) {
     strHql +=
         " and e.CUSTOMER_ALL_STATE LIKE('%" + customers.getState().toString().trim() + "%')";
   }
   // 客户名称的模糊查询
   if (null != customers.getCname() && !"".equals(customers.getCname().trim())) {
     strHql += " and e.CUSTOMER_ALL_CNAME LIKE('%" + customers.getCname().trim() + "%')";
   }
   System.out.println(strHql + "strHql");
   Query query = entityManager.createNativeQuery(strHql, Customers.class);
   if (null != start && null != limit) {
     if (0 == start) start = 1;
     query.setFirstResult((start.intValue() - 1) * limit);
     query.setMaxResults(limit.intValue());
   }
   return query.getResultList();
 }