配置数据源相关属性(见前一章节 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);
} }

整合MyBatis的更多相关文章

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

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

  2. Spring学习总结(六)——Spring整合MyBatis完整示例

    为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简 ...

  3. Spring学习总结(五)——Spring整合MyBatis(Maven+MySQL)二

    接着上一篇博客<Spring整合MyBatis(Maven+MySQL)一>继续. Spring的开放性和扩张性在J2EE应用领域得到了充分的证明,与其他优秀框架无缝的集成是Spring最 ...

  4. SpringMVC入门二: 1规范结构, 2简单整合MyBatis

    昨天拿springMVC写的helloworld结构不好, 这次先调整一下体系结构 , 然后简单整合一下MyBatis spring的配置还是以注解为主, 不过MyBatis的映射文件什么的还是拿xm ...

  5. 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  6. 2017年2月16日 分析下为什么spring 整合mybatis后为啥用不上session缓存

    因为一直用spring整合了mybatis,所以很少用到mybatis的session缓存. 习惯是本地缓存自己用map写或者引入第三方的本地缓存框架ehcache,Guava 所以提出来纠结下 实验 ...

  7. Spring Boot 整合 MyBatis

    前言 现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便 ...

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

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

  9. spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist

    spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path reso ...

  10. spring 整合Mybatis 《报错集合,总结更新》

    错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...

随机推荐

  1. 在Windows下编译Cef3.2623并加入mp3、mp4支持(附带源码包和最终DLL)《转》

    https://blog.csdn.net/zhuhongshu/article/details/54193842 源码包下载地址:点我下载 最终Dll.Lib.PDB.头文件下载地址(release ...

  2. 从内核3.7版本开始,Linux就开始支持VXLAN 到了内核3.12版本,Linux对VXLAN的支持已经完备,支持单播和组播,IPv4和IPv6。

    一.关于VXLAN VXLAN 是 Virtual eXtensible LANs 的缩写,它是对 VLAN 的一个扩展,是非常新的一个 tunnel 技术,在Open vSwitch中应用也非常多. ...

  3. 005 Spring和SpringBoot中的@Component 和@ComponentScan注解

    今天在看@ComponentScan,感觉不是太理解,下面做一个说明. 1.说明 ComponentScan做的事情就是告诉Spring从哪里找到bean 2.细节说明 如果你的其他包都在使用了@Sp ...

  4. postgre查询表和记录数,查表字段

    select relname as TABLE_NAME, reltuples as rowCounts from pg_class where relkind = 'r' and relnamesp ...

  5. Ionic4.x ion-refresher 下拉更新

    官方文档:https://ionicframework.com/docs/api/refresher <ion-header> <ion-toolbar> <ion-ti ...

  6. org/apache/curator/RetryPolicy at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter.connect(CuratorZookeeperTransporter.java:26)

    使用dubbo服务,启动项目报错: org/apache/curator/RetryPolicy at com.alibaba.dubbo.remoting.zookeeper.curator.Cur ...

  7. window.location.href重定向失败的问题

    如题,在js中通过window.location.href=URL来跳转到另一个页面(也可以是另一个项目的另一个页面). 打开的页面地址是:www.a.com/project1/index 要跳转的页 ...

  8. 【linux命令之 tail学习】

    tail 在屏幕上显示指定文件的末尾若干行 tail file #(显示文件file的最后10行) tail -n +20 file #(显示文件file的内容,从第20行至文件末尾) tail -c ...

  9. VS2010/VS2012/VS2015下openGL环境配置(转)

    按:按照下述博文,三个例子均成功. https://blog.csdn.net/so_geili/article/details/51685005 请仔细阅读每一个字. 为了学习<OpenGL超 ...

  10. SAS如何看待大数据

    SAS如何看待大数据 "大数据"现在是一个炙手可热的词语,数据分析师这个词虽然比较新,但收集与存储大量信息的历史却不短了. 早在本世纪初,行业分析师Doug Laney就提出了&q ...