寫在前面的話:在慕課網(wǎng)學(xué)習(xí)的時(shí)候,老師使用的是一般的web結(jié)構(gòu),更多的時(shí)候都是使用的mevan項(xiàng)目結(jié)構(gòu),所以這里呢就改成了mevan項(xiàng)目結(jié)構(gòu)。
【強(qiáng)調(diào)】在博客完成中,突然發(fā)現(xiàn)3.4.2中沒(méi)有org.apache.ibatis.session.SqlSession;這個(gè)類,請(qǐng)各位使用3.4.1版本,以后找時(shí)間再去完成這兩個(gè)版本的差異性更新
https://github.com/mybatis/mybatis-3/releases我們需要下載一個(gè)打包好的jar包以及源代碼,如圖所示:

如果你是使用的Maven搭建的項(xiàng)目,可以將下面的代碼拷貝到pom.xml文件中
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --><dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.2</version></dependency>此步驟如果是使用的Maven搭建可省略
找到下載好的這個(gè)壓縮包并解壓

打開解壓所得的文件夾

將mybatis-3.4.2.jar文件拷貝到web項(xiàng)目的WEB-INF/lib文件夾中即可
MySQL的jar包路徑同上
首先找到我們之前下載好的Mybatis源代碼

將其解壓,并打開解壓所得的文件夾

因?yàn)榕渲梦募0娴穆窂奖容^深,這里就不截圖展示了。
/mybatis-3-mybatis-3.4.2/src/test/java/org/apache/ibatis/submitted/complex_PRoperty/Configuration.xml將這個(gè)配置復(fù)制到web項(xiàng)目中,建議在web項(xiàng)目中創(chuàng)建一個(gè)包用于存放配置文件,如圖所示:
如果使用的是Maven搭建的項(xiàng)目結(jié)構(gòu),建議將配置文件存放在resources文件下,一樣的,也是從包名開始檢索

主要是修改配置文件中的數(shù)據(jù)庫(kù)驅(qū)動(dòng)、地址、數(shù)據(jù)庫(kù)名、用戶名、密碼等信息 另外注釋掉一部分暫時(shí)不需要的代碼
<?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"> <!-- 數(shù)據(jù)庫(kù)驅(qū)動(dòng),此處使用的是MySQL數(shù)據(jù)庫(kù) --> <property name="driver" value="com.mysql.jdbc.Driver"/> <!-- 數(shù)據(jù)庫(kù)地址以及數(shù)據(jù)庫(kù)的名字 --> <property name="url" value="jdbc:mysql://127.0.0.1:3306/mircro_message"/> <!-- 數(shù)據(jù)庫(kù)用戶名 --> <property name="username" value="user"/> <!-- 數(shù)據(jù)庫(kù)密碼 --> <property name="passWord" value="123456"/> </dataSource> </environment> </environments><!-- <mappers> <mapper resource="org/apache/ibatis/submitted/complex_property/User.xml"/> </mappers>--></configuration>由于在Mybatis中主要是通過(guò)SqlSeesion來(lái)訪問(wèn)數(shù)據(jù)庫(kù),所以我們需要單獨(dú)使用一個(gè)類來(lái)真正的去操作數(shù)據(jù)庫(kù)。

git地址:https://code.csdn.net/baofeidyz/mybatisstudypratice02mircromessage_no-2/tree/master 資源下載地址:http://download.csdn.net/detail/baofeidyz/9749383
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注