最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mybatis中的PageHelper的執(zhí)行流程分析

 更新時(shí)間:2022年02月28日 11:20:57   作者:樹_tree  
這篇文章主要介紹了Mybatis的PageHelper執(zhí)行流程,本文給大家介紹介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

PageHelper Mybatis的執(zhí)行流程

  • mybatis中首先要在配置文件中配置一些東西
  • 然后根據(jù)這些配置去創(chuàng)建一個(gè)會(huì)話工廠
  • 再根據(jù)會(huì)話工廠創(chuàng)建會(huì)話,會(huì)話發(fā)出操作數(shù)據(jù)庫的sql語句
  • 然后通過執(zhí)行器操作數(shù)據(jù)
  • 再使用mappedStatement對數(shù)據(jù)進(jìn)行封裝

這就是整個(gè)mybatis框架的執(zhí)行情況。

插件的執(zhí)行

它主要作用在Executor執(zhí)行器與mappedeStatement之間

也就是說mybatis可以在插件中獲得要執(zhí)行的sql語句

在sql語句中添加limit語句,然后再去對sql進(jìn)行封裝,從而可以實(shí)現(xiàn)分頁處理。

SpringBoot操作PageHelper

引入依賴

 <!--分頁插件 pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <!-- 特別注意版本問題 -->
            <version>1.2.13</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1</version>
        </dependency>

yaml配置

#整合數(shù)據(jù)源
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: ok
    url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
#Mybatis-Plus的配置
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 配置在控制臺(tái)打印 sql語句
  # 配置自定義sql語句的 *mapper.xml 文件位置
  mapper-locations: classpath:**/mapper/**.xml
pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

項(xiàng)目示例結(jié)構(gòu)

CategoryDao

因?yàn)槭褂昧薓ybatisPlus所以有些方法可以不去實(shí)現(xiàn),通過Plus自己編寫

@Mapper
public interface CategoryDao extends BaseMapper<Category> {
}

CateService接口

import cn.pojo.Category;
import java.util.*;
public interface CateService {
    public List<Category> pageSelect(int page,int col);
}

CateServiceImple實(shí)現(xiàn)

import javax.annotation.Resource;
import java.util.List;
@Service
public class CateServiceImple implements CateService {
    @Resource
    CategoryDao categoryDao;
    @Override
    public List<Category> pageSelect(int page, int col) {
//        使用分頁表明,從第幾頁開始,一頁多少條數(shù)據(jù)
        PageHelper.startPage(page,col);
		
//        使用Plus進(jìn)行查詢所有,因?yàn)镻ageHelper插件會(huì)進(jìn)行sql的limit的拼接
        List<Category> categories = categoryDao.selectList(null);

        return categories;
    }
}

核心代碼

//        使用分頁表明,從第幾頁開始,一頁多少條數(shù)據(jù)
        PageHelper.startPage(page,col);
//        使用Plus進(jìn)行查詢所有,因?yàn)镻ageHelper插件會(huì)進(jìn)行sql的limit的拼接
        List<Category> categories = categoryDao.selectList(null);

查看結(jié)果

到此這篇關(guān)于Mybatis的PageHelper的文章就介紹到這了,更多相關(guān)Mybatis的PageHelper內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

葵青区| 闽侯县| 九江县| 临沭县| 巴中市| 威海市| 永康市| 温宿县| 福清市| 涟水县| 延川县| 金山区| 肇州县| 桂阳县| 清苑县| 新野县| 庆城县| 阳高县| 宜兴市| 天等县| 富平县| 卢氏县| 大邑县| 建阳市| 仙桃市| 武鸣县| 天全县| 泰安市| 诏安县| 望都县| 钟山县| 若尔盖县| 信丰县| 新丰县| 沈阳市| 勃利县| 宁陕县| 扬中市| 苏尼特右旗| 桂阳县| 搜索|