ssm整合pageHelper插件

(1)在pom.xml中添加分頁插件的依賴

<!-- 分頁插件 -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.1.2</version>
</dependency>

(2)在mybatis中的配置文件SqlMapConfig.xml(這個名字是你自己搭建環境所取的,就是配置一些關於Mybatis的配置文件)添加分頁插件。

       <plugins>
		<!-- com.github.pagehelper爲PageHelper類所在包名 -->
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
			<!-- 設置數據庫類型Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種數據庫 -->
			<property name="helperDialect" value="mysql"/>
		</plugin>
	</plugins>

(3)在controller層或者service實現層中使用分頁。

/**
     * 查詢所有的person內容
     * @return
     */
    @RequestMapping(value = "/list")
    public String jumpJsp(Map<String, Object> result){
        PageHelper.startPage(1 , 8);
        List<Person> personList = personService.findPerson();
        //得到分頁的結果對象
        PageInfo<Person> personPageInfo = new PageInfo<>(personList);
        //得到分頁中的person條目對象
        List<Person> pageList = personPageInfo.getList();
        //將結果存入map進行傳送
        result.put("pageInfo" , pageList);
        return "person_list";
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章