1.首先先配置好好springboot。
2.在pom.xml文件中配置对应的dependency
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<!-- 这个是对应的启动器,里面包含默认的数据库连接池hikaricp连接池 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 配置这个是告诉用的是哪个数据库是,我这里是用的mysql数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<!--整合mybatis的启动器-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
3.在配置文件中配置对应的数据库数据
spring.datasource.password=test
spring.datasource.username=root
spring.datasource.url=jdbc:mysql:///test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
mybatis.type-aliases-package=配置包的别名
4.配置对应的mapper
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
public interface UserDao {
@Select("select * from user")
public List<User> findAll();
@Select("select * from user where id =#{id}")
public User findUserById(Integer id);
@Update("delete from user where id =#{id}")
public void deleteUserById(Integer id);
}
这样就整合好了mybatis。