ibatis,顾效率,iBatis一些非见用法(10条)

兼顾效率,iBatis一些非见用法(10条)
iBatis一些非见用法,基本上解决所有棘手问题,下面总结如下:
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字段
<!–DATA[
img_size >= #_img_size_ge#
]]>

<!–DATA[
img_size < #_img_size_lt#
]]>
多次使用一个参数也是允许的
<!–DATA[
execplantime >= #_now#
]]>

<!–DATA[
closeplantime <= #_now#
]]>
3、时间范围查询

<!–DATA[
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条件
<!–DATA[
(t.finished='11' or t.failure=3)
]]>

<!–DATA[
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,
 Tags:  ibatis教程 ibatis

延伸阅读

最新评论

发表评论