mybatis-config.xml

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--核心配置文件-->
<configuration>
    <properties resource="db.properties">
        <property name="username" value="admain"/>
        <property name="password" value="admain"/>
    </properties>
    <!--    可以给实体类起别名-->
    <typeAliases>
        <package name="com.kuang.pojo"/>
    </typeAliases>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>
    <!--    每一个mapperxml都需要在mybatis核心配置文件中注册-->
    <mappers>
        <package name="com.kuang.mapper"/>
    </mappers>
</configuration>

db.properties

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql:///mybatis?serverTimezone=UTC&userUnicode=true;
username=admain
password=admain

如果不用db.properties,直接就写在mybatis-config.xml中需要将&的转义字符

本文来自博客园,作者:CLAY——MRX,转载请注明原文链接:https://www.cnblogs.com/do-it-520/p/mybatis_config.html

韶华易逝,不能虚度年华。
原文地址:https://www.cnblogs.com/do-it-520/p/mybatis_config.html