Spring-Boot-Starter-Mybatis
基于Spring Boot和Mybatis,添加分页相关功能,免配置即可用
依赖
spring boot:1.5.6
mybatis-spring-boot-starter:1.3.1
cluster-common:1.2.2-RC
快速开始
- 添加依赖
<dependency>
<groupId>com.zerostech</groupId>
<artifactId>spring-boot-starter-mybatis</artifactId>
<version>${lastest.version}</version>
</dependency>
- JDBC配置
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test
schema: classpath:db/schema.sql
data: classpath:db/data.sql
- MyBatis配置
mybatis:
type-aliases-package: com.zeros.demo.model
type-handlers-package: com.zerso.demo.typehandler
configuration:
map-underscore-to-camel-case: true
default-fetch-size: 100
default-statement-timeout: 30
- 服务
@Mapper
public interface RoleDao {
@Select("SELECT * FROM t_role WHERE id = #{id}")
Role findById(@Param("id") int id);
@Select("SELECT * FROM t_role")
List<Role> fetchRoles();
}
@GetMapping
public Resp<Page<Role>> fetchRoles() {
MybatisPageContext.setPageRequest(new MybatisPageContext.PageRequest(1, 2));
roleDao.fetchRoles();
Page<Role> roleResponsePage = MybatisPageContext.getPage();
MybatisPageContext.clearAll();
return Resp.success(roleResponsePage);
}
演示
项目目录example/mybatis-demo