配置数据源相关属性(见前一章节 DataSource配置

引入依赖

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

application.properties

mybatis.mapper-locations=classpath:public/mybatis/mapper/*.xml
mybatis.config-location=classpath:public/mybatis/mybatis-config.xml

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> <settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>

EmployeeMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.springBoot01.mapper.EmployeeMapper">
<!-- public Employee getEmpById(Integer id); public void insertEmp(Employee
employee); --> <resultMap type="com.atguigu.springBoot01.entity.Employee" id="empMap">
<id column="id" property="id" />
<result column="lastName" property="lastName" />
<result column="email" property="email" />
<result column="gender" property="gender" />
<result column="department_id" property="department.id" />
</resultMap> <select id="getEmpById" resultMap="empMap">
SELECT * FROM t_employee WHERE id=#{id}
</select> <insert id="insertEmp" parameterType="com.atguigu.springBoot01.entity.Employee">
INSERT INTO t_employee(last_name,email,gender,department_id) VALUES
(#{lastName},#{email},#{gender},#{department.id})
</insert>
</mapper>

EmployeeMapper接口

package com.atguigu.springBoot01.mapper;

import com.atguigu.springBoot01.entity.Employee;

public interface EmployeeMapper {

    public Employee getEmpById(Integer id);

    public void insertEmp(Employee emp);

}

使用MapperScan批量扫描所有的Mapper接口

@SpringBootApplication
@MapperScan(value = "com.atguigu.springBoot01.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} }

最新文章

  1. Javascript随记
  2. SPSS数据分析—多分类Logistic回归模型
  3. html中的图片直接使用字符串代替
  4. ASP.Net页面刷新后自动滚动到原来位置
  5. BZOJ3012 : [Usaco2012 Dec]First!
  6. socket的异步回调函数,采用一问一答
  7. web前后台数据交互的四种方式(转)
  8. Effective Java 第三版——9. 使用try-with-resources语句替代try-finally语句
  9. Java核心技术(Java白皮书)卷Ⅰ 第一章 Java程序设计概述
  10. CSS3-2
  11. P61 实践作业
  12. 浅谈2017noip信息奥赛普及组试题
  13. visio连接线设置
  14. python定义类()中写object和不写的区别
  15. Unity shader学习之高光反射光照模型
  16. flask 使用Flask-SQLAlchemy管理数据库(连接数据库服务器、定义数据库模型、创建库和表)
  17. 本地PC安装Centos 6.5 操作手册及遇到的问题
  18. 【开源推荐】PredictionIO:构建预测功能的机器学习服务器
  19. C C++ 常被人问的问题分析
  20. Distinct Values(贪心)

热门文章

  1. [Linux] 60s快速分析Linux性能
  2. taocrypt
  3. GIS地理工具案例教程——批量去除多边形的之间的间隙
  4. windows中kill端口为8080的进程(或子进程)
  5. Prometheus基于consul自动发现监控对象 https://www.iloxp.com/archive/11/
  6. ntpd服务
  7. Socket通信(1):搭建开发环境
  8. 【插件式框架探索系列】使用多UI线程提升性能
  9. ES6深入浅出-8 新版的类(下集)-1.简单语法
  10. 安卓 android studio 报错 Lint found fatal errors while assembling a release target