springboot 集成mybatis

1:依赖mybaits分页插件

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

2:启动类中@MapperScan 扫描接口包

@MapperScan("com.jxd.Boot.mybatis.dao") // 启用mybatis
@SpringBootApplication //相当于上边几个的集合
//@EnableScheduling//开启定时任务注解
public class Application {
public static void main(String[] args) {

SpringApplication.run(Application.class, args);


}
}

 

3:mybatis 生成工具生成po mapper .xml

.xml 放到resource下

例如:

4:开启sql输出日志:application.properties中加入:

#打印mybatis日志
logging.level.com.jxd.Boot.atis.dao=debug

5:测试:

/**
* @Description (测试springboot集成mybatis 分页)
* @param no
* @param size
* @return
*/
@RequestMapping("/testmybatis")
public Object likeName(@RequestParam(defaultValue = "1") Integer no,
@RequestParam(defaultValue = "10") Integer size) {
MstudentExample ex = new MstudentExample();
PageHelper.startPage(no, size);
Page<Mstudent> list = (Page<Mstudent>) mstudentMapper.selectByExample(ex);
Pager pager = RenderPager.mybatisconverPager(list);
return pager;
}

posted @ 2018-05-31 16:24  洞玄巅峰  阅读(138)  评论(0编辑  收藏  举报