版本 ibatis 2.3.4
Spring 3.X
集成配置什么的都不说了
直接来些关键的代码:
Oracle存储过程:
create or replace PROCEDURE PROCEDURE1
( username IN VARCHAR2
, realname IN VARCHAR2
, userid OUT VARCHAR2
) AS
BEGIN
select user_id into userid
from sys_sec_user
where user_name like username
and real_name like realname;
END PROCEDURE1;
SQLMap中配置:
<parameterMap id="procParam" class="java.util.Map">
<parameter property="userName" mode="IN" javaType="java.lang.String" jdbcType="VARCHAR"/>
<parameter property="realName" mode="IN" javaType="java.lang.String" jdbcType="VARCHAR"/>
<parameter property="userId" mode="OUT" javaType="java.lang.String" jdbcType="VARCHAR"/>
</parameterMap>
<procedure id="callProc" parameterMap="procParam" resultClass="java.lang.String">
{ call PROCEDURE1(?, ?, ?) }
</procedure>
注意:
jdbcType参见java.sql.Types定义的常量。
入参对应每一个"?",顺序不能错误。
java Code如下:
SqlMapClient sqlMapper;
@Test
public void testProc(){
try {
Map<String,String> map = new HashMap<String, String>();
map.put("userName", "%z%");
map.put("realName", "%z%");
map.put("userId", null); //map.put("userId","")也可
sqlMapper.queryForObject("callProc", map);
System.out.println(map.get("userId"));
} catch (SQLException e) {
e.printStackTrace();
}
}