存储过程:
CREATE OR REPLACE
procedure P_TEST(v_cursor OUT sys_refcursor)
as
begin
OPEN v_cursor
FOR select POST_ID, FORUM_ID, USER_ID, POST_TITLE, POST_CONTENT, POST_TIME, TOTAL_COMMENT_COUNT from POST;
end;
resultMap:
<resultMap id="BaseResultMap" type="com.bbs.pojo.Post" >
<id column="POST_ID" property="postId" jdbcType="DECIMAL" />
<result column="FORUM_ID" property="forumId" jdbcType="DECIMAL" />
<result column="USER_ID" property="userId" jdbcType="DECIMAL" />
<result column="POST_TITLE" property="postTitle" jdbcType="VARCHAR" />
<result column="POST_CONTENT" property="postContent" jdbcType="VARCHAR" />
<result column="POST_TIME" property="postTime" jdbcType="TIMESTAMP" />
<result column="TOTAL_COMMENT_COUNT" property="totalCommentCount" jdbcType="DECIMAL" />
</resultMap>
<select id="testP" statementType="CALLABLE" >
{call P_TEST(#{v_cursor, mode=OUT, jdbcType=CURSOR, javaType=java.sql.ResultSet, resultMap=com.bbs.dao.PostMapper.BaseResultMap})}
</select>
注:
1. call语句左右的大括号可以去掉,但网上的好像很多都有写。
2. call语句与左右大括号间不能有空格或换行等,会报错(java.sql.SQLException: 出现不支持的 SQL92 标记: 1:)
test代码:
Map<String, Object> param = new HashMap<String, Object>();
postService.testP(param);
System.out.println((List<Post>) param.get("v_cursor"));