SSM框架crud(增删改查模糊查询加分页)之模糊查询(三)
发布日期:2021-10-12 20:07:57 浏览次数:17 分类:技术文章

本文共 10080 字,大约阅读时间需要 33 分钟。

 先上图:这个是正常查询没搜索分页之前

 搜索后带分页的

 

 效果图也看了,咱们上干货吧

首先分页得加一个工具类,里面有封装好的当前页,上一页,下一页等

public class PageUtil {	//页	private String page;	//每页数据量	private int pageSize;	//总数据数	private int count;		//当前页	private int currentPage;	//上一页	private int prevPage;	//下一页	private int nextPage;	//最后一页	private int lastPage;	//开始	private int startIndex;	//总页数	private int totalPage;				public int getTotalPage() {		return totalPage;	}	public void setTotalPage(int totalPage) {		this.totalPage = totalPage;	}	public PageUtil(String page, int pageSize, int count){		this.page = page;		this.pageSize = pageSize;		this.count = count;		initCurrentPage();		initPrevPage();		initLastPage();		initNextPage();		initStartIndex();		initTotalPage();	}	private void initTotalPage(){		if(count%pageSize!=0){			this.totalPage = count/pageSize+1;		}else{			this.totalPage = count/pageSize;		}	}	//当前页	private void initCurrentPage(){		page = page == null ? "1" : page;		currentPage = Integer.parseInt(page);	}		//上一页	private void initPrevPage(){		if(currentPage == 1){			prevPage = 1;		}else{			prevPage = currentPage - 1;		}	}		//最后一页	private void initLastPage(){		lastPage = count / pageSize;		if(count % pageSize != 0){			lastPage += 1;		}	}		//下一页	private void initNextPage(){		if(currentPage == lastPage){			nextPage = currentPage;		}else{			nextPage = currentPage + 1;		}	}		private void initStartIndex() {		startIndex = (currentPage - 1) * pageSize;	}	public String getPage() {		return page;	}	public int getPageSize() {		return pageSize;	}	public int getCount() {		return count;	}	public int getCurrentPage() {		return currentPage;	}	public int getPrevPage() {		return prevPage;	}	public int getNextPage() {		return nextPage;	}	public int getLastPage() {		return lastPage;	}		public int getStartIndex() {		return startIndex;	}	}

现在进入正题,这是列表页面

  

共${page.count}条记录/${page.totalPage}页
名称 发布时间 库存 总销量 药品分类 平台 / 状态 操作
${product.content } ${product.createTime }
已售罄
${product.countNum}
${product.sales }
其他(无标签)
${product.tagContent }
自营
商家
出售中
未上架
已删除
未出售
 详细信息  
 上架  
 下架  
 删除
 规格  

这个是js里面分页,查询传参,我这个查询得字段比较多,自己可以根据自己实际情况查询,分页后面也要把查询得字段拼接上。

/*	    *    模糊查询	 */	function search() {		var content = $("#content").val();		var approvalNumber = $("#approvalNumber").val();		var barcode = $("#barcode").val();		var startPrice = $("#startPrice").val();		var endPrice = $("#endPrice").val();		var startTime = $("#startTime").val();		var endTime = $("#endTime").val();		var startSales = $("#startSales").val();		var endSales = $("#endSales").val();		var countNum = $("#countNum").val();		var saleType = $("#saleType").val();		var sort = $("#sort").val();		var symptom = $("#symptom").val();		var department = $("#department").val();		var place = $("#place").val();		var brand = $("#brand").val();		var status= '${map.status}';		var sSales=/^[0-9]*[1-9][0-9]*$/;		var eSales=/^[0-9]*[1-9][0-9]*$/;		if((sSales.test(startSales)&&sSales.test(endSales))||(startSales==""&&endSales=="")){		location.href = "/user/system/productMangerList?content="				+ content + "&approvalNumber=" + approvalNumber				+ "&barcode=" + barcode + "&startPrice="+startPrice+"&endPrice="+endPrice+"&startTime=" + startTime + "&endTime="				+ endTime+"&startSales=" + startSales+"&endSales="+endSales				+ "&countNum=" + countNum + "&saleType=" + saleType+"&brand="+brand+"&status="+status; 		}else{			  layer.alert("您输入的格式不正确,请输入大于0的正整数!!!!");		}	}	/*	  * 分页	 */	function fenye(cpage) {		var status= '${map.status}';		var content = $("#content").val();		var approvalNumber = $("#approvalNumber").val();		var barcode = $("#barcode").val();		var startPrice = $("#startPrice").val();		var endPrice = $("#endPrice").val();		var startTime = $("#startTime").val();		var endTime = $("#endTime").val();		var startSales = $("#startSales").val();		var endSales = $("#endSales").val();		var countNum = $("#countNum").val();		var saleType = $("#saleType").val();		var sort = $("#sort").val();		var symptom = $("#symptom").val();		var department = $("#department").val();		var place = $("#place").val();		var brand = $("#brand").val();		location.href = "/user/system/productMangerList?cpage=" + cpage				+ "&content=" + content + "&approvalNumber=" + approvalNumber					+ "&barcode=" + barcode + "&startPrice="+startPrice+"&endPrice="+endPrice					+ "&startTime=" + startTime + "&endTime="					+ endTime+"&startSales=" + startSales+"&endSales="+endSales					+ "&countNum=" + countNum + "&saleType=" + saleType+"&brand="+brand+"&status="+status; 	    }

下一步我在看Controller控制层

/*	 * 跳转商品管理主页面	 */	@RequestMapping(value = "productMangerList")	public String productMangerList(HttpServletRequest request,Model model, String status, String saleType,String content			,String approvalNumber,String barcode,String startPrice,String endPrice,			String startSales,String endSales,String countNum			,String sort,String symptom,String department,String place,String brand,String cpage) {	     		String type = (String) request.getSession().getAttribute("role");		if ("1".equals(type)) {			log.info("-------------------》商户---没该权限");			return "redirect:errorPower";		}else if ("2".equals(type)) {			log.info("-------------------》管理员专属权限---商品管理");		String requestURL = request.getRequestURL().toString();//获取链接路径		String mathodPath = requestURL.substring(requestURL.lastIndexOf("/")+1);//截取最后一个字段		List
querySjManager = userService.queryMenuPermission(); if (!"".equals(mathodPath)) { for (MenuPath menu : querySjManager) { if (mathodPath.equals(menu.getPurl())) {//判断是否有这个权限 log.info("由此权限,放过!!!!"); Map
map = new HashMap
(); map.put("request",request); map.put("status", status); map.put("saleType",saleType); map.put("content", content); map.put("approvalNumber", approvalNumber); map.put("barcode", barcode); map.put("startPrice",startPrice); map.put("endPrice",endPrice); map.put("startSales",startSales); map.put("endSales",endSales); map.put("countNum",countNum); map.put("sort",sort); map.put("symptom",symptom); map.put("department",department); map.put("place",place); map.put("brand",brand); int count = productService.getProductCount(map); PageUtil page = new PageUtil(cpage, Page_SIZE, count); map.put("page",page); List
productList = productService.queryProductList(map); request.setAttribute("productList", productList); request.setAttribute("page", page); model.addAttribute("map", map); return "product/productManage"; } } } } return "redirect:errorPower"; }

controller对应得接口

List
queryProductList(Map
map);//列表查询 int getProductCount(Map
map);//分页

 业务逻辑层

/** 	 * 

Title:getProductCount

*

Description: 计算每页商品的数量

*

Copyright: Copyright (c) 2018

*

Company: www.zhaoge.com

* @author zhaowenjun * @date * @version 1.0 */ @Override public int getProductCount(Map
map) { return productMapper.getProductCount(map); }/** *

Title: queryProductList

*

Description:

*

Copyright: Copyright (c) 2018

*

Company: www.zhaoge.com

* @author zhaowenjun * @date * @version 1.0 */ @Override public List
queryProductList(Map
map) { return productMapper.queryProductList(map); }

mapper接口层

List
queryProductList(Map
map); int getProductCount(Map
map);

mybatis配置:sql

到此为止了

转载地址:https://blog.csdn.net/qq_39772439/article/details/90634781 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:复选框全选全不选反选加批量删除
下一篇:SSM框架crud(增删改查模糊查询加分页)之查询修改(二)

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月08日 01时12分27秒