zoukankan      html  css  js  c++  java
  • pageHelper分页

    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;

    @Controller
    public 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";
    }


    }
  • 相关阅读:
    统计学习及监督学习概论(2)
    推荐系统(1)
    统计学习及监督学习概论(1)
    JavaScript学习08 Cookie对象
    JavaScript学习07 内置对象
    JavaScript学习06 JS事件对象
    JavaScript学习05 定时器
    JavaScript学习04 对象
    JavaScript学习03 JS函数
    JavaScript学习02 基础语法
  • 原文地址:https://www.cnblogs.com/leigepython/p/10112737.html
Copyright © 2011-2022 走看看