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"; }}
来源:https://www.cnblogs.com/leigepython/p/10112737.html