pom文件:

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>

步骤:

​ 1)、配置数据源相关属性(见上一节Druid)

​ 2)、给数据库建表

​ 3)、创建JavaBean

注解版:

//指定这是一个操作数据库的mapper
@Mapper
public interface DepartmentMapper { @Select("select * from department where id=#{id}")
public Department getDeptById(Integer id); @Delete("delete from department where id=#{id}")
public int deleteDeptById(Integer id); @Options(useGeneratedKeys = true,keyProperty = "id")
@Insert("insert into department(departmentName) values(#{departmentName})")
public int insertDept(Department department); @Update("update department set departmentName=#{departmentName} where id=#{id}")
public int updateDept(Department department);
}

问题:

自定义MyBatis的配置规则;给容器中添加一个ConfigurationCustomizer;

@org.springframework.context.annotation.Configuration
public class MyBatisConfig {

@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer(){

@Override
public void customize(Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
}

配置文件版:

mybatis:
config-location: classpath:mybatis/mybatis-config.xml 指定全局配置文件的位置
mapper-locations: classpath:mybatis/mapper/*.xml 指定sql映射文件的位置

 
 
 
 
 
 
 
 
 

整合MyBatis(springboot)的更多相关文章

  1. MyBatis原理,Spring、SpringBoot整合MyBatis

    1. MyBatis概述 MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可 ...

  2. springBoot整合Mybatis,Junit

    笔记源码:https://gitee.com/ytfs-dtx/SpringBoot 整合Mybatis SpringBoot的版本:2.2.5.RELEASE Mybatis版本:mybatis-s ...

  3. springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件

    整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...

  4. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  5. SpringBoot整合Mybatis,多数据源,事务,支持java -jar 启动.

    用了一段时间SpringBoot,之前配置MYBATIS ,在打包WAR 放到tomcat下正常,但是WAR已经过时了,现在流行直接打包JAR 丢到DOCKER 里,无奈JAR 启动的时候MAPPER ...

  6. SpringBoot当中如何整合mybatis和注入

    [学习笔记] 6.整合mybatis和注入: 马克-to-win@马克java社区: 根据第3部分的helloworld例子,用那个项目做底子.pom.xml只需要加入mybatis和mysql的部分 ...

  7. SpringBoot整合Mybatis【非注解版】

    接上文:SpringBoot整合Mybatis[注解版] 一.项目创建 新建一个工程 ​ 选择Spring Initializr,配置JDK版本 ​ 输入项目名 ​ 选择构建web项目所需的state ...

  8. 展开被 SpringBoot 玩的日子 《 六 》 整合 Mybatis

    上次整合了JPA ,但是很多人觉得JPA 并不是那么好用,这都是习惯问题,我本人也比较习惯Mybatis ,所以,今天就整合一下Mybatis,到网上找了一下关于spring boot和mybatis ...

  9. SpringBoot整合系列-整合MyBatis

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971036.html SpringBoot整合Mybatis 步骤 第一步:添加必要的j ...

  10. springboot整合mybatis(使用MyBatis Generator)

    引入依赖 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> ...

随机推荐

  1. springboot+mybatis+druid数据库连接池

    参考博客https://blog.csdn.net/liuxiao723846/article/details/80456025 1.先在pom.xml中引入druid依赖包 <!-- 连接池 ...

  2. Eclipse+pydev+手动安装

    1.Eclipse中手动安装pydev插件 解决:Eclipse版本中的windows-performance下面无法显示pydev的情况 1.Eclipse版本是:Version: Luna Ser ...

  3. post方式接口测试(一)_新建测试用例

    第一种方式:拷贝别人的 第二种方式:自己创建 二.打开浏览器(此处chrome),F12打开开发模式,输入网址登录,此时可获取到登录的 Request URL 二.打开postman,进入自己的Col ...

  4. git:当本地分支中的代码和develop分支上有很多冲突,希望删掉本地分支,重新建立新的分支,怎么解决?

    git:当本地分支中的代码和develop分支上有很多冲突,希望删掉本地分支,重新建立新的分支,但是git中说你需要先解决当前的冲突,这种情况怎么解决 这种情况可以在代码编辑器中点击commit,然后 ...

  5. Android studio中导入SlidingMenu问题

    我们导入的library文件夹中的build.gradle 文件里面写的很清楚: android {     compileSdkVersion 17     buildToolsVersion &q ...

  6. PHP中array_merge和array+array的区别

    在PHP中可以使用array_merge函数和两个数组相加array+array的方式进行数组合并,但两者效果并不相同,区别如下: 当下标为数值时,array_merge()不会覆盖掉原来的值,但ar ...

  7. 要学的javaee技术

    mybatis.hibernate.spirng MVC.freemarker.zookeeper.dubbo.quartz的技术框架:NoSQL技术ehcache.memcached.redis等: ...

  8. [LeetCode] 62. Unique Paths_ Medium tag: Dynamic Programming

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  9. 《More Accurate Question Answering on Freebase》文献笔记

    bast-2015-CIKM CIKM全称是International Conference on Information and Knowledge Management 这篇文章主要采用采用lea ...

  10. Cocos Creator - 入门教程项目 - 博客频道 - CSDN.NET

    3457 教程司令部 [20160418] | Cocos Creator - CocoaChina CocoaChina_让移动开发更简单cocoachina.com 2033 Cocos Crea ...