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映射文件的位置

 
 
 
 
 
 
 
 
 

最新文章

  1. Eclipse创建Maven工程报错
  2. cocos初认识
  3. Java设计模式(一)——代理模式
  4. Linux的一些常用快捷键和基本命令
  5. Xml序列化UTF-8格式错误
  6. [ html canvas getImageData Object.data.length ] canvas绘图属性 getImageData Object.data.length 属性讲解
  7. npm 打包 electron app 报错问题
  8. C#启动进程之Process
  9. mysql deadlock
  10. C++语法细节笔记
  11. butternife Zelezny自动注入插件
  12. 通过flask实现web页面简单的增删改查bootstrap美化版
  13. 22.LinkedList
  14. Luogu1081 NOIP2012 开车旅行 倍增
  15. iOS 11开发教程(二十)iOS11应用视图美化按钮之设置按钮的状态
  16. event.stopPropagation(),event.preventDefault()和return false的区别
  17. OpenCV 图形变换
  18. CSS 实例之打开大门
  19. Python3:if __name__ == &#39;__main__&#39; 详解
  20. VS Code 折腾记 - (5) Angular 2+ &amp;&amp; Typescript 2 + 必备插件推荐

热门文章

  1. pytorch--nn.Sequential学习
  2. python基础(7)-函数&amp;命名空间&amp;作用域&amp;闭包
  3. block,inline和inline-block概念和区别(转载)
  4. openshift 容器云从入门到崩溃之九《容器监控-报警》
  5. 59.phpstudy升级Mysql的正确姿势
  6. Unity之获取资源包的路径
  7. sublime开启vim模式
  8. GreenDao 使用和数据库升级
  9. Delphi中有关窗口绘制
  10. ATM Mechine (概率DP)