Mybatis常用傳參、返參、存儲過程、函數使用歸納

1、傳單個參數

dao中 : public String queryOneRecpt(String projectid); // 或者(@Param("projectid")String projectid)

xml中:

select e.projectid as projectid,e.tiltle as tiltle, COM_GET_SPLICGINGUSERNAME(e.bmtdesc) as bmtdesc from notes_exami e where e.parentid = #{ parentid , jdbcType=varchar }

其中 COM_GET_SPLICGINGUSERNAME(e.bmtdesc) 是對字段操作的函數,返回字符串。

4、返回集合、SQL循環

dao中: public List getItemPhaseList ( ItemPhaseInfoVO info) ;

xml中:

select t.id as id , t.projectid as projectid , rt.sn as sn from notes_ItemPhaseInfo t

where upper( t.sn) like ( ' %' || upper( trim (#{ sn , jdbcType=varchar }) ) || ' %' ) // upper 是 Oracle轉大寫

and t.phaseCount in

#{item} // foreach 循環類似於 t.phaseCount in (1,2)

order by t.phaseCount

5、保存時主鍵序列

dao中 : public int saveAcceptionInfo ( AcceptionVO acceptionVO);

xml中 :

select notes_examin_s.nextval from dual

insert into notes_examin(

projectId, parentId , sn , title

) values ( #{ projectId , jdbcType=varchar } ,

#{ parentId , jdbcType=varchar } ,

#{ sn, jdbcType=varchar } ,

#{ title, jdbcType=varchar }

)

調用保存方法後VO對象中就有了主鍵projectI值, 也就是說: dao.saveAcceptionInfo ( acceptionVO);log.info( acceptionVO.id ); // 可打印出來

6、調用存儲過程

dao中: public Map cancdsubitem(Map paramMap);

xml中:

select get_pack_budget ( #{type} , #{businessid} ) from dual

select >

8、調用函數返回集合對象

< include refid=" query_base " >

from phase_item t

where < include refid="query_condition" >

e.projectid as projectid , e.sn as sn

e.projectid = #{ projectid , jdbcType=varchar }

10 、返回嵌套查詢

太熱了,該做飯了,每一個我討厭的現在,都有一個恥辱的曾經!!!


分享到:


相關文章: