Java

Java中Mybatis配置步骤

勤劳的小蜜蜂 · 4月22日 · 2019年 ·

Mybatis jar包

配置步骤

//复制mybatis的jar包到lib文件中,全选,右键添加到build path中
//创建com.ye.mapper的包

//创建StudnetMapper的接口
public interface StudentMapper(){
    pbulic student getStudent(int id){};
}

//复制xml文件重命名为StudentMapper.xml到com.ye.mapper路径下
<mapper namespace="com.ye.mybatis.StudentMapper">
    <select id="getStudnet" ParameterType="int" resultType="com.ye.studnet">
        seclect * from student where id=#{id}
    </seclect>
<mapper>

//复制mybatis-config.xml到src路径下
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManage type="JDBC" />
            <datasourse type="POOLED">
                <property name="driver" value="com.mysql.jdbc.driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/stubase" />
                <property name="username" value="root" />
                <property name="password" value="root" />
            </datasourse>
        </environment>
    </environment>
    <mappers>
        <mapper resourse="com/ye/mapper/StudentMapper.xml">
    </mappers>
</configuration>

目录结构

0 条回应