文章标题
来源:互联网 发布:java如何使用log4j 编辑:程序博客网 时间:2024/06/03 14:17
1). 引入 Jar 包
你可以从下面的地址中下载最新版本的 jar 包
https://oss.sonatype.org/content/repositories/releases/com/github/pagehelper/pagehelper/
http://repo1.maven.org/maven2/com/github/pagehelper/pagehelper/
由于使用了sql 解析工具,你还需要下载 jsqlparser.jar:
http://repo1.maven.org/maven2/com/github/jsqlparser/jsqlparser/0.9.5/
2).config.xml的配置:
< configuration>
< plugins>
< plugin interceptor=”com.github.pagehelper.PageHelper”>
< property name=”helperDialect” value=”mysql”/>
< property name=”pageSizeZero” value=”true”/>
< property name=”reasonable” value=”true”/>
< /plugins>
<mappers> <mapper resource="sqlMapper.xml"/> <!-- 我的这个sqlMapper在src根目录下,所以没有包名称--> </mappers>
3).sqlMapper映射文件中我写了一个查询所有的方法:
SELECT * FROM student
4).对应的接口dao写一个查询所有的方法:
//分页测试public List<Student> selectByPageAndSelections();
5).为了方便我把实现方法和测试方法写在一起了
package Test;
import java.util.List; import org.apache.ibatis.session.SqlSession; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import common.SqlSessions; import dao.StudentDao; import enterty.Student; public class StudentTest {SqlSession session=SqlSessions.getSession();StudentDao sDao=session.getMapper(StudentDao.class); public PageInfo<Student> selectDocByPage1(int currentPage, int pageSize) { PageHelper.startPage(currentPage, pageSize);//设置当前页,和每页的查询数量 List<Student> list = sDao.selectByPageAndSelections(); PageInfo<Student> pageInfo = new PageInfo<>(list); return pageInfo; } //main方法测试 public static void main(String[] args) { StudentTest test=new StudentTest(); PageInfo<Student> page=test.selectDocByPage1(2,0); //System.out.println(list.getFirstPage()); List<Student> list = page.getList(); for (Student s : list) { System.out.println(s.getName()); } }
}
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- ListView常用优化技巧
- Tensorflow实例:实现Word2Vec(Skip-Gram模式)
- halcon学习基础
- navicat for mysql还原备份psc后缀文件报Unknown storage engine 'InnoDB'
- DOM和BOM-day22-个人学习笔记
- 文章标题
- (未完)Writeup of Take the maze (reverse) in BugKu
- Ubuntu14-04安装redis和php5-redis扩展
- JavaScript--事件
- windows下搭建MQTT服务器--Apollo--LG二进制
- 线程二
- 成绩统计
- normalize.css用这个来设置默认样式,不要用reset.css
- 【头条】中国OpenStack开源力量都在解决哪些关键性应用?