开发之路十二——Mybatis

2022-07-06  本文已影响0人  林几许

1,springboot中mybatis二级缓存

1,配置文件打开二级缓存

mybatis:
    configuration:
        local-enalbled:true

2,在mapper.xml文件中添加

<catch></catch>

3,实体类序列化

public class Student implements Serializable

总结:

2,springboot中mybatis使用pageHelper实现分页查询

1,导入依赖

     <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.12</version>
    </dependency>

2,在application.properties或者application.yml格式配置pagehelper的属性

   pagehelper.helper-dialect=mysql
        pagehelper.reasonable=true
        pagehelper.support-methods-arguments=true
        pagehelper.params=count=countSql
  hepagehelper:
          lperDialect: mysql
          reasonable: true
          supportMethodsArguments: true
          params: count=countSql

3,在controller层调用

      PageHelper.startPage(1,5);
      List<CarTable> carTables = service.findallCar()
      PageInfo<CarTable> page = new PageInfo<CarTable>(carTables);
上一篇 下一篇

猜你喜欢

热点阅读