---
title: "真分页查询时点击下一页要将查询条件再次传给Controller"
author: "Edie"
date: "2012-05-17T16:58:35Z"
tags: []
categories: ["移动开发"]
slug: "controller"
draft: false
lastmod: "2012-05-17T17:00:36Z"
id: 1533899
url: "https://edie.iteye.com/blog/1533899"
---

1）多条件查询（多个条件在一个对象中）

真分页查询就是每点击下一页时，程序就要再次查询数据库，但查询的起点是从上一次查询的下一条开始。在第一次查询时，条件肯定是可以传过去的，在点下一页的时候:

```
<@p.pager pager = ordersListPage  baseUrl = "/order/pageOrderList.htm?orderId=${orderId}&orderType=${orderType}&startTime=${startTime}&endTime=${endTime}&phone=${phone}" parameterMap = parameterMap />

```

 

URL中将所要查询的条件都要传给Controller，在Controller代码如下：

```
 @RequestMapping("/pageOrderList")
    public String pageQuery(VgsBackstageOrderQueryParam pageQueryParam, ModelMap model) {
        String orderType = pageQueryParam.getOrderType();
        Logger log = LoggerFactory.getLogger(this.getClass());
        log.info("the info is" + pageQueryParam.getPageNumber());
        log.info("the info is" + pageQueryParam.getOrderId());

        QueryResult<BackstageDTO> queryResult = backstageOrderService
                .pageQueryOrderList(pageQueryParam);
        if (null == queryResult.getDatas() || queryResult.getDatas().size() == 0) {
            model.addAttribute("noResult", true);
        }

        model.addAttribute("orderList", queryResult.getDatas());
        model.put("ordersListPage", queryResult);
        model.addAttribute("orderId", pageQueryParam.getOrderId())
                .addAttribute("orderType", orderType)
                .addAttribute("phone", pageQueryParam.getPhone())
                .addAttribute("startTime", pageQueryParam.getStartTime())
                .addAttribute("endTime", pageQueryParam.getEndTime());

        return "backstage/orderList.ftl";

    }
```

 

1）多条件查询（没有将多个条件定义在一个对象中）

在页面中：

```
<@p.pager pager = param  baseUrl = "/BCS/findCustomerByParam_${customerName}_${customerSex}_${customerCompany}_${customerTel}.htm" parameterMap = parameterMap /> 

在Controller中：

@RequestMapping("/findCustomerByParam_{customerName}_{customerSex}_{customerCompany}_{customerTel}")
 // 从页面传来客户的多个条件
 public String findCustomerByParam(
   @PathVariable("customerName") String customerName,
   @PathVariable("customerSex") String customerSex,
   @PathVariable("customerCompany") String customerCompany,
   @PathVariable("customerTel") String customerTel, ModelMap model,
   PageQueryParam param) {

. . . . . . 

}

```

 

用@PathVariableURL占位符来设置页面传过来的条件，注意@RequestMapping中的写法。