创建存储过程
create PROCEDURE pro1(in name1 VARCHAR(20),out num INTEGER)BEGINinsert into dept (dname) values (name1);select count(*) into num from dept;END
创建mapper
<parameterMap id="pro1" type="java.util.Map"><parameter property="dname" mode="IN" jdbcType="VARCHAR"/><parameter property="num" mode="OUT" jdbcType="INTEGER"/></parameterMap><insert id="testPro" parameterMap="pro1" statementType="CALLABLE">call pro1(?,?);</insert>
JDBC 要求,如果一个列允许 null 值,并且会传递值 null 的参数,就必须要指定 JDBC Type映射文件还可以这样写:
运行测试:
public static void main(String[] args) throws IOException {SqlSessionFactory sql = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));SqlSession sqlSession = sql.openSession();DempDAO mapper = sqlSession.getMapper(DempDAO.class);Map map=new HashMap<>();map.put("dname", "设计部");map.put("num", 0);mapper.testPro(map);mit();System.out.println(map.get("num").toString());}