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 、返回嵌套查询

太热了,该做饭了,每一个我讨厌的现在,都有一个耻辱的曾经!!!


分享到:


相關文章: