1. pom.xml添加依赖
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
2. 在application.properties添加配置,需要扫面的实体包,xml文件所谓位置,mybatis的位置
#------------------------------------mybatis--------------------------------
mybatis.type-aliases-package=com.caiwufei.entity
mybatis.mapper-locations=classpath:/mybatis/mappers/**/*.xml
mybatis.config-location=classpath:/config/mybatis-config.xml
3 在配置类或者启动类添加map对应接口需要扫描的包
@MapperScan(basePackages= {"com.caiwufei.module.*.dao"})
4 接口
package com.caiwufei.module.employees.dao;
import java.util.List;
import com.caiwufei.entity.base.BaseMapper;
import com.caiwufei.entity.employees.Department;
public interface DepartmentDao extends BaseMapper<Department>{
List<Department> selectAll();
}
5 mapper的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.caiwufei.module.employees.dao.DepartmentDao">
<select id="selectAll" resultType="Department">
select * from departments;
</select>
</mapper>