码迷,mamicode.com
首页 > 编程语言 > 详细

springboot 集成mybatis

时间:2018-05-31 16:42:26      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:bye   ram   integer   ble   image   bug   http   enc   dep   

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;
}

springboot 集成mybatis

标签:bye   ram   integer   ble   image   bug   http   enc   dep   

原文地址:https://www.cnblogs.com/coderdxj/p/9117380.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!