使用KKpage 分页插件在java代码中的写法,

@RequestMapping(value = "/queryMerchant.do", method = { RequestMethod.GET,RequestMethod.POST })
	public String queryMerchant(HttpServletRequest request,HttpServletResponse response) {

		//确定分页时传递的参数
	     int allNum=wholesalerService.findAllNum();                         //查询一共有多少条记录
	     int num=10;                                                                                     //定义每页显示的数据条数
	     request.setAttribute("totalCount",allNum);                            //数据总条数
	     request.setAttribute("totalPage",(allNum-1)/num+1);         // 总页数
	     int pno=Integer.parseInt( request.getParameter("pno"));   //当前页码

	   //   未进行分页的代码
	  //   List<QueryMerchantInfo> wholesalerList=wholesalerService.findAllMerchantInfo();
	  //   request.setAttribute("wholesalers",wholesalerList);
	     
	       //查询全部数据放入List1中
	         List<QueryMerchantInfo> wholesalerListNew= new ArrayList<QueryMerchantInfo>();
	    	wholesalerListNew=wholesalerService.findAllMerchantInfo();
	    	
	    	//定义一个要显示的List2
	    	  List<QueryMerchantInfo> wholesalerListNewShow= new ArrayList<QueryMerchantInfo>();
	    	 
	    	 // 根据网页传递的参数,选择放入List2中的值
	        for(int i =((pno-1)*num+1);i<=(((pno*num)>allNum)?allNum:(pno*num));i++)
	        {
			        QueryMerchantInfo queryMerchantInfo=wholesalerListNew.get(i-1);
			        wholesalerListNewShow.add(queryMerchantInfo);
	        }
	     
	        request.setAttribute("wholesalers",wholesalerListNewShow);
	   
		return "/moderator/queryMerchantList";
		
	}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
假设你使用的是 Java Spring Boot 框架,可以使用 MyBatis 分页插件进行分页查询。 首先,在 pom.xml 添加 MyBatis 分页插件的依赖: ```xml <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> ``` 然后,在需要进行分页查询的方法,调用 PageHelper.startPage() 方法开启分页功能,并传入当前页码和每页显示据条,如下所示: ```java import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public PageInfo<User> getUsers(int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); List<User> users = userMapper.getUsers(); return new PageInfo<>(users); } } ``` 在上面的代码,我们调用了 PageHelper.startPage() 方法开启分页功能,并传入了当前页码和每页显示据条。然后,我们调用 UserMapper 接口的 getUsers() 方法来获取所有用户据,并将其封装成 PageInfo 对象返回。 最后,我们可以在控制器调用 getUsers() 方法来获取分页据,并将其返回给前端页面显示,如下所示: ```java @RestController public class UserController { @Autowired private UserService userService; @GetMapping("/users") public PageInfo<User> getUsers(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) { return userService.getUsers(pageNum, pageSize); } } ``` 在上面的代码,我们使用 @GetMapping 注解来处理 GET 请求,并通过 @RequestParam 注解来获取请求参的当前页码和每页显示据条。然后,我们调用 UserService 接口的 getUsers() 方法来获取分页据,并将其返回给前端页面显示。 至此,我们就完成了后端使用分页插件实现分页查询的代码编写。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值