一、环境
开发工具:idea
jdk:1.7
mysql:5
框架:spring+springmvc+mybatis
使用maven来管理项目
二、与ssm整合
- 第一步:在pom.xml引入PageHelper的依赖
<!-- 引入mybatis的 pagehelper 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.2</version> </dependency>
- 第二步:在mybatis的全局配置文件中配置PageHelper分页插件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 引入 pageHelper插件 --> <!--注意这里要写成PageInterceptor, 5.0之前的版本都是写PageHelper, 5.0之后要换成PageInterceptor--> <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <!--reasonable:分页合理化参数,默认值为false,直接根据参数进行查询。 当该参数设置为 true 时,pageNum<=0 时会查询第一页, pageNum>pages(超过总数时),会查询最后一页。--> <!--<property name="reasonable" value="true"/>--> </plugin> </plugins> </configuration>
三、使用
例如:实现对用户的多条件查询
- User实体类
package com.szfore.model; import java.util.Date; import java.util.List; public class User { private Integer id; private String uname; private String pwd; private String name; private Integer sex; private String phone; private String company; private String jobtitle; private String birth; private Date createdate; private Date lastlogintime; private List<Role> roleList; public List<Role> getRoleList() { return roleList; } public void setRoleList(List<Role> roleList) { this.roleList = roleList; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname == null ? null : uname.trim(); } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd == null ? null : pwd.trim(); } public String getName() { return name; } public void setName(String name) { this.name = name == null ? null : name.trim(); } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone == null ? null : phone.trim(); } public String getCompany() { return company; } public void setCompany(String company) { this.company = company == null ? null : company.trim(); } public String getJobtitle() { return jobtitle; } public void setJobtitle(String jobtitle) { this.jobtitle = jobtitle == null ? null : jobtitle.trim(); } public String getBirth() { return birth; } public void setBirth(String birth) { this.birth = birth == null ? null : birth.trim(); } public Date getCreatedate() { return createdate; } public void setCreatedate(Date createdate) { this.createdate = createdate; } public Date getLastlogintime() { return lastlogintime; } public void setLastlogintime(Date lastlogintime) { this.lastlogintime = lastlogintime;