spring boot引入mybatis

Updated on in 程序人生 with 0 views and 0 comments

1.建立springboot工程引入依赖

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

2.yml中进行mybatis的配置

主要是指定mapper.xml的位置 

mybatis: 
  mapper-locations: classpath*:/mapper/*Mapper.xml 
  type-aliases-package: com.csg.spider.bean 
  configuration: 
  log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl 
  map-underscore-to-camel-case: true 
  cache-enabled: false 
  jdbc-type-for-null: null 

Pagehelper使用默认配置 

3.启动类中使用@MapperScan注解表明dao曾接口位置

@MapperScan(basePackages = {"com.csg.spider.dao"})

4.分页实例

service层次 

public List  getPage(int pageNum, int pageSize) { 
  PageHelper.startPage(pageNum,pageSize,false,false,true); 
  List  all = spiderDao.getAll(); 
  return toVos(all); 
} 

Dao层 

List getAll();

Mybatis的xml 

<select id="getAll" resultType="com.csg.spider.bean.Spider"> 
select * from spider 
</select> 

标题:spring boot引入mybatis
作者:wenyl
地址:http://www.wenyoulong.com/articles/2020/05/26/1590490347706.html