Ejemplo n.º 1
0
 /**
  * dao删除
  *
  * @throws ActionException
  */
 public <T> Boolean delete(Class<T> entityClass) throws ActionException {
   try {
     if (entityClass == null) throw new ActionException("entityClass must be defined in Action");
     T t = entityClass.newInstance();
     this.buildPageData(t);
     baseModelService.delete(t);
     request.setAttribute("result", "success");
     return true;
   } catch (Exception e) {
     logger.error(e, e);
     request.setAttribute("result", "fail");
     return false;
   }
 }
Ejemplo n.º 2
0
 /**
  * 分页查询
  *
  * @throws ActionException
  */
 public <T> PageBean pageQuery(Class<T> entityClass) throws ActionException {
   if (entityClass == null) throw new ActionException("entityClass must be defined in Action");
   String page = request.getParameter("page");
   String pageSize = request.getParameter("pageSize");
   PageBean pageBean =
       baseModelService.pageQuery(
           bulidConditionSql(),
           bulidOrderBySql(),
           Integer.valueOf(pageSize),
           Integer.valueOf(page),
           entityClass);
   request.setAttribute("pageBean", pageBean);
   return pageBean;
 }
Ejemplo n.º 3
0
  public String bulidConditionSql() {
    StringBuffer sql = new StringBuffer();
    Map<String, String> queryMap = new HashMap<String, String>();
    String orderSql = "";
    Map paramMap = request.getParameterMap();
    for (Iterator itor = paramMap.keySet().iterator(); itor.hasNext(); ) {
      Object key = itor.next();
      Object object = paramMap.get(key);
      if (key instanceof String && key.toString().startsWith(SEARCH_CODE) && object != null) {
        String queryKey = String.valueOf(key).substring(SEARCH_CODE.length());
        if (object.getClass().isArray()) {
          Object[] sValue = (Object[]) object;
          String value = sValue[0].toString();
          if (value.trim().isEmpty()) continue;
          queryMap.put(queryKey, value);
        }
      }
      if (key instanceof String && key.toString().startsWith(SEARCH_ORDER_CODE) && object != null) {
        if (object.getClass().isArray()) {
          Object[] sValue = (Object[]) object;
          String value = sValue[0].toString();
          if (value.trim().isEmpty()) continue;
          orderSql = value;
        }
      }
    }
    String queryMapSql = baseModelService.buildSQLWhere(queryMap);
    if (!StringUtils.isEmpty(condition)) {
      sql.append(condition);
    }
    if (!StringUtils.isEmpty(queryMapSql)) {
      sql.append(queryMapSql);
    }

    return sql.toString();
  }
Ejemplo n.º 4
0
 public <T> T findOne(Integer id, Class<T> entityClass) throws DaoException {
   return (T) baseModelService.findOne(id, entityClass);
 }
Ejemplo n.º 5
0
 /**
  * dao查询
  *
  * @throws ActionException
  * @throws DaoException
  */
 public <T> List<T> query(Class<T> entityClass) throws ActionException, DaoException {
   if (entityClass == null) throw new ActionException("entityClass must be defined in Action");
   List<T> resultList = baseModelService.find(condition, entityClass);
   request.setAttribute("resultList", resultList);
   return resultList;
 }