`

Spring中的使用WebUtils.getParametersStartingWith(request, "search_");

 
阅读更多

前台页面:

<table cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
     <tr>
      <td  style="width:260px">登录名:<input type="text" name="search_loginid" value="${filter['loginid']}"/></td>
      <td  style="width:260px">公司名称:<input type="text" name="search_companyName" value="${filter['companyName']}"/></td>
      <td>
    状态:<select name="search_status">
      <option value="">请选择</option>
        <c:forEach items="${userStatusEnum}" var="type">
         <option value="${type.key}"  ${filter['status'] eq type.key?'selected':''}>${type.value}</option>
        </c:forEach>
      </select>
    </td>
      <td align="left">&nbsp;&nbsp;<input type="submit"  style="width:80px" value="查询" class="button" onclick="document.searchForm.submit();"/></td>
     </tr>
    </table>

后台获取数据:

Map<String, Object> filter = WebUtils.getParametersStartingWith(
    request, "search_");

数据库查询:

public Page findBy(Map filterMap, Map orderMap, int pageNo, int pageSize) {
  Criteria criteria = getSession().createCriteria(getEntityClass());
  String loginid  = (String)filterMap.get("loginid");
  if(StringUtils.isNotEmpty(loginid)){
   criteria.add(Restrictions.like("loginid", "%"+loginid+"%"));
  }
  String name  = (String)filterMap.get("name");
  if(StringUtils.isNotEmpty(name)){
   criteria.add(Restrictions.like("name", "%"+name+"%"));
  }
  String status  = (String)filterMap.get("status");
  if(StringUtils.isNotEmpty(status)){
   criteria.add(Restrictions.eq("status", status));
  }
  String type  = (String)filterMap.get("type");
  if(StringUtils.isNotEmpty(type)){
   criteria.add(Restrictions.eq("type", type));
  }
  String companyId = (String)filterMap.get("companyId");
  if(StringUtils.isNotEmpty(companyId)){
   criteria.add(Restrictions.eq("companyId", companyId));
  }
  criteria.createAlias("Company", "companys_");
  String companyName = (String)filterMap.get("companyName");
  if(StringUtils.isNotEmpty(companyName)){
   criteria.add(Restrictions.like("companys_.name", "%"+companyName+"%"));
  }
  if (!CollectionUtils.isEmpty(orderMap)) {
   sortCriteria(criteria, orderMap, null);
  }
  criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
  return pagedQuery(criteria, pageNo, pageSize);
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics