iBatis動態SQL標籤用法

2022-05-25 19:00:09 字數 2124 閱讀 1479

1、動態sql片段

通過sql片段達到**復用

select count(*)

select *

from icp

name like '%$name$%'

path like '%path$%'

area_id = #area_id#

hided = #hided#

limit #_start#, #_size#

2、數字範圍查詢

所傳引數名稱是捏造所得,非資料庫字段,比如_img_size_ge、_img_size_lt欄位

img_size >= #_img_size_ge#

]]>

img_size < #_img_size_lt#

]]>

多次使用乙個引數也是允許的

execplantime >= #_now#

]]>

closeplantime <= #_now#

]]>

3、時間範圍查詢

createtime >= #_starttime#

and createtime < #_endtime#

]]>

4、in查詢

state in ('$_in_state$')

5、like查詢

(chnameone like '%$chnameone$%' or spellinitial like '%$chnameone$%')

chnametwo like '%$chnametwo$%'

6、or條件

(t.finished='11' or t.failure=3)

]]>

t.finished in ('10','19') and t.failure<3

]]>

7、where子查詢

code not in

(select t.contentcode

from cms_ccm_programcontent t

where t.contenttype='mznrlx_ma'

and t.programcode = #exprogramcode#)

select *

from cms_ccm_material

where code in

(select t.contentcode

from cms_ccm_programcontent t

where t.contenttype = 'mznrlx_ma'

and programcode = #value#)

order by updatetime desc

9、函式的使用

insert into rulemaster(

name,

createtime,

updatetime,

remark

) values (

#name#,

now(),

now(),

#remark#

)select last_insert_id()

update rulemaster set

name = #name#,

updatetime = now(),

remark = #remark#

where id = #id#

10、map結果集

select count(a.*)

select a.id vid,

a.img imgurl,

a.img_s imgfile,

b.vfilename vfilename,

b.name name,

c.id sid,

c.url url,

c.filename filename,

c.status status

from secfiles c, juji b, videoinfo a

where

a.id = b. videoid

and b.id = c.segmentid

and c.status = 0

order by a.id asc,b.id asc,c.sortnum asc

limit #_start#, #_size#

iBatis動態SQL標籤用法

ibatis動態sql標籤用法 1 動態sql片段 通過sql片段達到 復用 select count select from icp name like name path like path area id area id hided hided limit start size 2 數字範圍查...

MyBatis 動態sql標籤

findbyaccount parametertype com.lin.entity.account resulttype com.lin.entity.account select from account test id 0 id if test username null and userna...

動態SQL常用標籤

select from blog title and author preparing select from blog where title select from blog where author 這裡的and被自動去掉了 select from blog where title and a...