MyBatis学习笔记

Stella981
• 阅读 613

MyBatis配置文件

mybatis-config.xml 元素可以指定properties文件位置,导入里面配置的值 定义了一些别名,如student,用来代替全名com..Student 元素配置mapper.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>
    <properties resource="com/endless/mybatis/helloworld/config/jdbc.properties" />
    <typeAliases>
        <typeAlias alias="student" type="com.endless.mybatis.helloworld.po.Student"></typeAlias>
    </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>
    <mappers>
        <mapper resource="com/endless/mybatis/helloworld/config/student-mapper.xml" />
    </mappers>
</configuration>

jdbc.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/school
username=root
password=1234

mapper配置文件

student-mapper.xml 这个文件里面配置sql,namespace为对于DAO接口