pageHelper分页

徘徊边缘 提交于 2019-12-28 11:22:53
package com.example.controller;import com.example.entity.User;import com.example.service.UserService;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controllerpublic class UserController {    @Autowired    private UserService userService;    @RequestMapping("/all")    @ResponseBody    public PageInfo<User> all(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "2") int pageSize){        /**         * pagehelper分页有法         * 该函数返回PageInfo<User>对象         */        // 第一步  确定页码,包括当前与,以前一页显示多少条        PageHelper.startPage(page,pageSize);        // 第二步:查询构建结果集        List<User> users = userService.showAllUser();        // 第三步:用PageInfo来返回结果集,里面包括数据,以及分页的详细情误        PageInfo<User> userPageInfo = new PageInfo<>(users);        return  userPageInfo;    }    @RequestMapping("/del")    public String delUser(String email){        int i = userService.deleteUser(email);        System.out.println("删除了:"+i+"条数据");        // 重定向        return "redirect:/all";    }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!