MyBatis基础:MyBatis调用存储过程(6)

1. 存储过程准备

CREATE PROCEDURE sp_task 
(
    IN userId INT
)
BEGIN
    SELECT
        *
    FROM
        task
    WHERE
        user_id = userId;
END

2. MyBatis调用存储过程

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.libing.helloworld.dao.ITaskDao">
    <resultMap id="baseResultMap" type="com.libing.helloworld.model.Task">
        <id property="id" column="id" />
        <result property="userId" column="user_id" />
        <result property="taskName" column="task_name" />
        <result property="content" column="content" />
        <result property="createdDate" column="created_date" javaType="java.util.Date" jdbcType="DATE" />
    </resultMap>

    <select id="findTasksByUserId" statementType="CALLABLE" resultMap="baseResultMap">
        <![CDATA[
            {
                CALL sp_task(#{userId, jdbcType=INTEGER, mode=IN})
            }
        ]]>
    </select>
</mapper>

 

posted @ 2017-09-20 19:43  libingql  阅读(220)  评论(0编辑  收藏  举报