十二:Page分页加带过滤器的按条件查询

Action:

public String getList() throws Exception {

      try {

        List filters = PropertyFilter

              .buildFromHttpRequest(Struts2Utils.getRequest());

        // 设置分页条数

        page.setPageSize(StringValueUtils.getInt(Struts2Utils.getRequest()

              .getParameter("pagesize")));

        // 设置跳转页

        page.setPageNo(StringValueUtils.getInt(Struts2Utils.getRequest()

              .getParameter("page"), 1));

        page = cusTagManager.findPage(page, filters);

        String result = super.reverseLigerGridJsonData(page);

        Struts2Utils.renderText(result);

      } catch (Exception e) {

        logger.error("获取标签列表数据时出错", e);

      }

      returnNONE;

   }

Service:

//按条件查询

   @Transactional(readOnly = true)

   public Page findPage(final Page page,final List filters){

      String hql="select c from Custag c where 1 = 1";

      for(PropertyFilter filter:filters){

        String filterName =filter.getPropertyName();     

        String filterValue = filter.getMatchValue().toString();

        if(filterName.equals("name")){

           if(filterValue.equals("")){

              continue;            

           }         

           hql +=" and c.name like'%"+filterValue+"%'";

        }

      }

      returncusTagDao.findPage(page, filters);   

   }

Dao:

Jsp:

url: "custag!getList.action",

你可能感兴趣的:(SpringSide)