Mybatis框架注解开发

一、导入Mybatis和Mysql的依赖

二、编写mysql连接的配置文件

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>
    <environments default="mysql">
        <environment id="mysql">
            <transactionManager type="JDBC">transactionManager>
            
            <dataSource type="POOLED">

                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
                <property name="username" value="root"/>
                <property name="password" value="root"/>
            dataSource>
        environment>
    environments>

    <mappers>
        <mapper resource="com/mepu/dao/IMyBatisDao.xml">mapper>
    mappers>
configuration>

 

三、编写Dao接口

public interface IMyBatisDao {
    //查询所有的方法
    @Select("select * from user")
    public List findAll();
}

 

 

你可能感兴趣的:(Mybatis框架注解开发)