Eclipse上Mybatis的配置

一、Mybatis简介

    MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

二、下载

jar下载地址https://github.com/mybatis/mybatis-3/releases

jar和源码,源码中含有Mybatis的核心配置文件

三、导入

    1.解压下载文件

      

             第一个为源码文件,第二个为jar文件

    2.导入eclipse

    3.拷贝核心配置文件

            文件路径:

mybatis-3-mybatis-3.4.6/src/test/java/org/apache/ibatis/submitted/complex_property/Configuration.xml

            文件内容:

<?xml version="1.0" encoding="UTF-8" ?>
<!--


       Copyright 2009-2016 the original author or authors.


       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at


          http://www.apache.org/licenses/LICENSE-2.0


       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.


-->
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>
  <settings>
    <setting name="useGeneratedKeys" value="false"/>
    <setting name="useColumnLabel" value="true"/>
  </settings>


  <typeAliases>
    <typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
  </typeAliases>


  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC">
        <property name="" value=""/>
      </transactionManager>
      <dataSource type="UNPOOLED">
        <property name="driver" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:mem:complexprop"/>
        <property name="username" value="sa"/>
      </dataSource>
    </environment>
  </environments>


  <mappers>
    <mapper resource="org/apache/ibatis/submitted/complex_property/User.xml"/>
  </mappers>


</configuration>

在原配置文件的基础上进行修改,如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>
 
  <settings>
    <setting name="useGeneratedKeys" value="false"/>
    <setting name="useColumnLabel" value="true"/>
  </settings>
 <!--
  <typeAliases>
    <typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
  </typeAliases> -->

  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC">
        <property name="" value=""/>
      </transactionManager>
      <dataSource type="UNPOOLED">
        <property name="driver" value="com.mysql.jdbc.Driver"/><!-- 数据库驱动 -->
        <property name="url" value="jdbc:mysql://localhost:3306/Message"/><!-- 数据库路径 -->
        <property name="username" value="root"/><!-- 用户名 -->
        <property name="password" value="root"/><!-- 密码 自己添加的项 -->
      </dataSource>
    </environment>
  </environments>

  <mappers>
    <mapper resource="从src开始算起"/><!-- User.xml路径配置 -->
  </mappers>

</configuration>


Mybatis的简单使用:

         

    


  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值