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. spark组件笔记

    SparkContext 中最重要的3个组建: 1 TaskScheduler (包含两个内容,TaskSchedulerImpl和SparkDeploySchedulerBackend)-用于向Ma ...

  2. DNSmasq介绍

    DNSmasq介绍 转载自:http://www.cnblogs.com/demonxian3/p/7472300.html#top 云主机的mac地址由物理机的dnsmasq随机分配,如果要修改ma ...

  3. xampp lampp 改变网页root目录的方法

    This is an old question but I haven't seen it properly answered yet. Here is what you need to do: In ...

  4. python进阶之 线程编程

    1.进程回顾 之前已经了解了操作系统中进程的概念,程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别就在于:程序是指令的集合,它是进程 ...

  5. rosetta geometric constraint file(用于match和design)

    cst(constraint file)文件示例: CST::BEGIN TEMPLATE:: ATOM_MAP: atom_name: C6 O4 O2 TEMPLATE:: ATOM_MAP: r ...

  6. git bash支持中文

    打开Git Bash窗口-->右键-->Options-->text Locale:设置为zh_CN Charachter set:设置为UTF-8 保存,重新打开Git Bash, ...

  7. 改写pipeline

    为什么要改写方法:get_media_requests,他们的区别在哪里 def get_media_requests(self, item, info):#原始的 return [Request(x ...

  8. 在java中,将String类型字符串s赋值为null后,将字符串与其他字符串拼接后得到结果出现了null字符串与其他字符连接的样式

    String s = null; s  += "hello"; System.out.println(s); 结果为:nullhello 原因: 先应用String.valueOf ...

  9. AES,BigInteger,MD5加密

    http://tool.oschina.net/apidocs/apidoc?api=jdk-zh package cn.com.gome.cashier.web; import java.lang. ...

  10. week_one-python用户登录

    作业:编写登陆接口 输入用户名密码认证成功后显示欢迎信息输错三次后锁定 1.先创建锁文件account_lock.txt,内容可以为空2.再创建用户密码信息文件account.txteg.wo 123 ...