SpringBoot_thymeleaf_mybatis和PageHelper分页插件整合

package wx.demo.controllers;
/*

  • 作者:planetwalker
    *Conctroller类
  • */
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import wx.demo.entity.UserInfo;
import wx.demo.service.UserInfoService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Controller
public class WebController {

@Resource
private UserInfoService userInfoService;
@RequestMapping("/")
public ModelAndView Pages(@RequestParam(required=true,defaultValue="1")Integer page, HttpServletRequest request){
    //pageNum为页面数pageSize为数据条数
    PageHelper.startPage (page,3);

    List list =  userInfoService.selectByList ();
    request.setAttribute ("page",page);
    ModelAndView modelAndView=new ModelAndView("index");
    PageInfo p=new PageInfo(list);
    modelAndView.addObject ("userInfolist",list);
    modelAndView.addObject ("page",p);
    return modelAndView;
}

}

实体层
package wx.demo.entity;
/*

  • 作者:planetwalker

  • */

    public class UserInfo {
    private Integer id;
    private String email;
    private String username;
    private String password;
    private String dateTime;

     public Integer getId() {
         return id;
     }
    
     public void setId(int id) {
         this.id = id;
     }
    
     public String getEmail() {
         return email;
     }
    
     public void setEmail(String email) {
         this.email = email;
     }
    
     public String getUsername() {
         return username;
     }
    
     public void setUsername(String username) {
         this.username = username;
     }
    
     public String getPassword() {
         return password;
     }
    
     public void setPassword(String password) {
         this.password = password;
     }
    
     public String getDateTime() {
         return dateTime;
     }
    
     public void setDateTime(String dateTime) {
         this.dateTime = dateTime;
     }
    
     @Override
     public String toString() {
         return "UserInfo{" +
                 "id=" + id +
                 ", email='" + email + '\'' +
                 ", username='" + username + '\'' +
                 ", password='" + password + '\'' +
                 ", dateTime=" + dateTime +
                 '}';
     }
    

    }

分页插件的pom.xml


	com.github.pagehelper
	pagehelper-spring-boot-starter
	1.2.3

分页页面




    
    index
    


登录|注册
编号 用户名 密码 注册时间 修改 删除
edit delete

你可能感兴趣的:(springboot整合)