一、MySQL的sql分页语句
SELECT *
FROM table
LIMIT (currentPage-1)*pageSize,pageSize;
二、创建项目并导包(准备工作)
1. 这里我创建的是动态web项目
2. 导包(没有jar包的可以去maven下载)
3.创建mybatis.cfg.xml
<?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>
<properties resource="db.properties"></properties>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<!-- 配置数据库的连接
default:默认使用哪一个数据库连接
-->
<environments default="mysql">
<environment id="mysql">
<!-- 事务管理 使用JDBC的事务 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 使用什么数据库连接池 durid -->
<dataSource type="POOLED">
<property name="driver" value="${dirver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!-- 配置映射 -->
<mappers>
<mapper resource="com/lasing/mapping/UserMapping.xml"/>
</mappers>
</configuration>
4. 创建db.properties
#修改数据库username,password,url为自己的数据库
dirver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/springdemo
username=root
password=123456
5. 创建User实体类(记得在mysql创建数据库和表)
package com.lasing.domain;
import java.util.Date;
public class User {
private Integer id;
private String name;
private String address;
private Date birthday;
public User() {
}
public User(String name, String address, Date birthday) {
this.name = name;
this.address = address;
this.birthday = birthday;
}
public User(Integer id, String name, String address, Date birthday) {
this.id = id;
this.name = name;
this.address = address;
this.birthday = birthday;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String