mybatis中sql中的特殊符號

2021-08-10 13:36:11 字數 1806 閱讀 8947

1.

prefix:在trim標籤內sql語句加上字首。

suffix:

在trim標籤內sql語句加上字尾。

suffixoverrides:指定去除多餘的字尾內容,如:suffixoverrides=",",去除trim標籤內sql語句多餘的字尾","。

prefixoverrides:

指定去除多餘的字首內容

2.下面是乙個往購物車表中插入資料的mybatis語句

"insert"

parametertype=

"com.tortuousroad.groupon.cart.entity.cart"

>  

insert into cart  

"("suffix=

")"suffixoverrides=

",">  

test=

"id != null"

>  

id,  

if>  

test=

"userid != null"

>  

user_id,  

if>  

test=

"dealid != null"

>  

deal_id,  

if>  

test=

"dealskuid != null"

>  

deal_sku_id,  

if>  

test=

"count != null"

>  

count,  

if>  

test=

"createtime != null"

>  

create_time,  

if>  

test=

"updatetime != null"

>  

update_time,  

if>  

"values ("

suffix=

")"suffixoverrides=

",">  

test=

"id != null"

>  

#,  

if>  

test=

"userid != null"

>  

#,  

if>  

test=

"dealid != null"

>  

#,  

if>  

test=

"dealskuid != null"

>  

#,  

if>  

test=

"count != null"

>  

#,  

if>  

test=

"createtime != null"

>  

#,  

if>  

test=

"updatetime != null"

>  

#,  

if>  

假設沒有指定

suffixoverrides=

","

執行的sql語句也許是這樣的:insert into cart (id,user_id,deal_id,) values(1,2,1,);顯然是錯誤的

指定之後語句就會變成

insert into cart (id,user_id,deal_id) values(1,2,1);這樣就將「,」去掉了。

Mybatis 特殊SQL的執行

1.模糊查詢 測試模糊查詢 param mohu return list testmohu param mohu string mohu select id testmohu resulttype user select from t user where username like select ...

mybatis中的動態sql

if元素用法 select id role name as rolename note from t role where id and role name like concat choose when othersize元素用法 這三個元素充當了switch語句 select role no,r...

mybatis中的動態SQL

動態sql的基本元素 if 單條件分支判斷 choose,when,otherwise 多條件分支判斷 trim,set,where 用於處理sql拼裝問題 foreach 迴圈語句 bind 定義乙個上下文變數 test 用於判斷條件是否成立 if條件判斷語句 當角色名稱不為空時,根據角色名稱查詢...