IDEA Mybatis動態SQL語句使用

2021-10-18 10:49:19 字數 2924 閱讀 6677

/**

* 根據引數條件查詢user

* @param user

* @return

*/user getuserbyparameter

(user user)

;/**

* 修改一條user記錄

* @param user

*/void

update

(user user)

;/**

* 根據id集合獲取相對應user記錄

* @param idlist

* @return

*/list

getuserbycollection

(list

idlist)

;

"getuserbyparameter"

resulttype

="user"

>

select * from t_user where 1 = 1

test

="username != null"

>

and username = #

if>

test

="password != null"

>

and password = #

if>

select

>

"getuserbyparameter"

resulttype

="user"

>

select * from t_user

>

test

="username != null"

>

and username = #

if>

test

="password != null"

>

and password = #

if>

where

>

select

>

"update"

>

update t_user

>

test

="username != null"

>

username = #,if

>

test

="password != null"

>

password = #,if

>

set>

where id = #

update

>

字首where運用

"getuserbyparameter"

resulttype

="user"

>

select * from t_user

prefix

="where"

prefixoverrides

="and | or"

>

test

="username != null"

>

and username = #

if>

test

="password != null"

>

and password = #

if>

trim

>

select

>

字首set運用

"update"

>

update t_user

prefix

="set"

suffixoverrides

=","

>

test

="username != null"

>

username = #,if

>

test

="password != null"

>

password = #,if

>

trim

>

where id = #

update

>

/**

* 根據id集合獲取相對應user記錄

* @param idlist

* @return

*/list

getuserbycollection

(@param

("idlist"

) list

idlist)

;

"getuserbycollection"

resulttype

="user"

>

select * from t_user where id in

collection

="idlist"

item

="item"

open

="("

separator

=","

close

=")"

>

#foreach

>

select

>

③測試

@test

public

void

test06()

}

⑤結果

mybaties輸入引數,結果型別,動態sql整理

parametertype 可以是別名或者全限定名,他接受簡單型別pojo,hashmap。1.1 簡單型別。select id finduserbyid parametertype int resulttype user select from user where id 1.2 傳遞pojo包裝...

ORACLE中帶引數 REF游標及動態SQL例項

帶 引數的游標 declare dept code emp.deptno type 宣告列型別變數三個 emp code emp.empno type emp name emp.ename type cursor emp cur deptparam number is select empno,en...

SQ 模糊查詢

between.and.在資料庫內部是做作特殊優化的,執行效率比 and 等這種方式快 between a and b 相當於 字段 a and欄位 b 例如 select from dbo.mystudent where s age between 20 and 30 between and還可以...