007.Mybatis入门

1.在Mybatis的pom.xml文件中添加依赖

       <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.11</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.17</version>
        </dependency>

2.全局配置文件(mybatis-config.xml)(src/main/resources)

<?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>

<!-- 环境,可以配置多个,default:指定采用哪个环境 -->
<environments default="dev">

<!-- id:唯一标识 -->
<environment id="dev">
<!--采用JDBC进行事务的管理commit/rollback-->
<transactionManager type="JDBC"/>
<!-- 数据源,连接池类型的数据源 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/babytun?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="197366"/>
</dataSource>
</environment>

</environments>

</configuration>

 

posted @ 2022-11-01 01:43  李林林  阅读(12)  评论(0编辑  收藏  举报