sql脚本:查询
CREATE DEFINER=`root`@`localhost` PROCEDURE `queryCountByClassId`(IN classId INT, OUT scount int )
BEGIN
SELECT COUNT(*) INTO scount FROM stu WHERE class_id = classId ;
END
mapper.xml
<select id="queryCountByClassId" statementType="CALLABLE" parameterType="HashMap">
{
call queryCountByClassId(
#{classId,jdbcType=INTEGER,mode=IN},
#{sCount,jdbcType=INTEGER,mode=OUT}
)
}
</select>
mapper
void queryCountByClassId(Map<String,Object> map);
sql脚本:删除
CREATE DEFINER=`root`@`localhost` PROCEDURE `deleteStuByno`(in stuId int)
BEGIN
delete from stu where stu_id = stuId;
END
mapper.xml
<delete id="deleteStuByno" parameterType="HashMap" statementType="CALLABLE">
call deleteStuByno(
#{stuNo,jdbcType=INTEGER,mode=IN}
)
</delete>
mapper
void deleteStuByno(Map<String,Object> map);
笔记:
mode:表示存储过程的 输入或输出的类型 有 in、out 、inout
其中 通过statementType="CALLABLE"设置SQL的执行方式是存储过程。 存储过程的输入参数gName需要通过HashMap来指定
在使用时,通过hashmap的put方法传入输入参数的值;通过hashmap的Get方法 获取输出参数的值。
要注意Jar问题:ojdbc6.jar不能在 调存储过程时 打回车、tab,但是ojdbc7.jar可以。
如果报错: No enum constant org.apache.ibatis.type.JdbcType.xx,则说明mybatis不支持xx类型,需要查表。
存储过程 无论输入参数是什么值,语法上都需要 用map来传递该值;
只要 是 <transactionManager type=“JDBC” />,则增删改都需要手工commit ;