1. 匯入jar包:
2. 在src下新建全域性配置檔案(編寫jdbc的四個變數)
2.1 沒有名稱和位址要求
2.2 在全域性配置檔案中引入dtd或schema
2.2.1 如果匯入 dtd 後沒有提示
window--> preference --> xml --> xml catalog --> add 按鈕
2.3 全域性配置檔案內容
xmlversion
="1.0"
encoding
="utf-8"
?>
doctype
configuration
public
"- config 3.0//en"
"">
<
configuration
>
<
environments
default
="development"
>
<
environmentid=
"development"
>
<
transactionmanager
type
="jdbc"
>
transactionmanager
>
<
datasource
type
="pooled"
>
<
property
name
="driver"
value
="com.mysql.cj.jdbc.driver"
/>
<
property
name
="username"
value
="root"
/>
<
property
name
="password"
value
="root"
/>
<
property
name
="url"
value
="jdbc:mysql://localhost:3306/flower?useunicode=true&characterencoding=utf-8&servertimezone=utc"
/>
datasource
>
environment
>
environments
>
<
>
<
resource
=/>
>
configuration
>
3.1 檔案作用:編寫需要執行的sql命令
3.2 把xml理解成實現類
3.3 xml檔案內容
xmlversion
="1.0"
encoding
="utf-8"
?>
doctype
public
>
<
namespace
=>
<
selectid=
"selectall"
resulttype
="com.pojo.flower"
>
select * from tb_flower
select
>
>
4. 測試結果(只有在單獨使用mybatis時使用,最後ssm整合下面**不需要編寫)
publicclass
test_mybatiscatch
(ioexception e)
sqlsessionfactory
factory
=new
sqlsessionfactorybuilder().build(
is);
sqlsession
session
= factory
.opensession();
list
list
= session
.selectlist(
);for
(flower
flower
: list
) } }
mybatis環境搭建
1.需要在src下面搭建乙個mybatis config.xml的檔案 2.需要配置當前的xml檔案 oracle.jdbc.driver.oracledriver 這裡是驅動 jdbc oracle thin localhost 1521 orcl 這是配置url xmlversion 1.0 e...
Mybatis環境搭建
1.pom.xml 依賴資訊 mysqlgroupid mysql connector j aartifactid 8.0.11version dependency junitgroupid junitartifactid 4.12version dependency log4jgroupid lo...
MyBatis學習 環境搭建
一 匯入相關的jar 二 在 src 下新建全域性配置檔案 在全域性配置檔案中引入 dtd 或 schema,然後具體些mybatis的配置資訊 最基本的配置 主要是 1.配置資料庫連線的資料來源,相當於在原生的jbdc中的建立connection物件的過程,所需要的資料來源。乙個mybatis的全...