使用pagitation实现分页功能

后台controller代码

	@RequestMapping("/brand/list.do")
	public String brandList(String name, Integer isDisplay, Integer pageNo, ModelMap modelMap) {
		Brand brand = new Brand();
		StringBuilder sb = new StringBuilder();
		if (StringUtils.isNotBlank(name)){
			brand.setName(name);
			sb.append("name=").append(name);
		}
		if(isDisplay !=null){
			brand.setIsDisplay(isDisplay);
			sb.append("&").append("isDisplay=").append(isDisplay);
		}else{
			brand.setIsDisplay(1);
			sb.append("&").append("isDisplay=").append(1);			
		}
		brand.setIsDisplay(isDisplay);
		brand.setPageNo(Pagination.cpn(pageNo));
		brand.setPageSize(5);

		Pagination pagination = brandService.getBrandWithPage(brand);
		
		String url = "/brand/list.do";
		pagination.pageView(url, sb.toString());
		modelMap.addAttribute("pagination", pagination);
		modelMap.addAttribute("name", name);
		modelMap.addAttribute("isDisplay", isDisplay);
		return "brand/list";
	}

service代码

	@Transactional(readOnly = true)
	public Pagination getBrandWithPage(Brand brand) {
		Pagination pagination = new Pagination(brand.getPageNo(), brand.getPageSize(), brandDao.getBrandCount(brand));
		pagination.setList(brandDao.getBrandWithPage(brand));
		return pagination;
	}

前台代码

	<div class="page pb15">
		<span class="r inb_a page_b">
			<c:forEach items="${pagination.pageView }" var="page">
			${page}
		</c:forEach>
		 </span>
	</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值