MyBatis學習總結(三)

2021-08-27 18:50:01 字數 1026 閱讀 3174

一、連線資料庫的配置單獨放在乙個properties檔案中

1、在src目錄下新建乙個db.properties檔案,在db.properties檔案編寫連線資料庫需要使用到的資料庫驅動,連線url位址,使用者名稱,密碼:

driver=com

.mysql

.jdbc

.driver

url=jdbc:mysql://localhost:3306/mybatis

name=root

password=xdp

2、在mybatis的conf.xml檔案中引用db.properties檔案:

<?xml version="1.0" encoding="utf-8"?>

resource="db.properties"/>

default="development">

id="development">

type="jdbc" />

type="pooled">

name="driver"

value="$" />

name="url"

value="$" />

name="username"

value="$" />

name="password"

value="$" />

datasource>

environment>

environments>

configuration>

二、為實體類定義別名,簡化sql對映xml檔案中的引用

1.parametertype=」me.gacl.domain.user」這裡寫的實體類user的全類名me.gacl.domain.user,可以簡寫為:

insert into users(name,age) values(#,#)

前提實在conf.xml檔案中標籤中新增配置:

typealiases>

Mybatis學習總結(三) 實戰

前面兩篇文章已經簡單介紹了mybatis並且講述了如何快速搭建mybatis環境,本文簡單介紹專案開發中主要用到的功能點,包括以下知識點 1.resultmap的編寫 2.基本select 3.update語句,標籤 4.單層foreach的用法 5.delete語句 6.轉義 符號 7.動態sql...

Mybatis學習總結

mybatis 1.目前最主流的持久層框架為hibernate與mybatis,而且國內目前情況使用mybatis的公司比hibernate要多。2.hibernate學習門檻不低,要精通門檻更高。門檻高在怎麼設計o r對映,在效能和物件模型之間如何權衡取得平衡,以及怎樣用好hibernate快取與...

Mybatis學習總結

使用過程 新增依賴 新增配置檔案 通過mybatis config得到sqlsessionfactory 使用sqlsession操作要執行的sql語句 非執行緒安全,使用後關閉 全域性配置檔案mybatis config.xml 資料庫資訊 全域性設定 cacheenabled一般設為false不...