mybatis 3 调用mysql存储过程 并接受返回值

问题解决了,重新编辑下。见答案。
摸索的好痛苦,找不到官方文档的任何说明。 网上很多说法都是错的。
这种接口性的东西,这么多年了,为啥都没有文档,还是我没找到??

阅读 5.4k
1 个回答

总算解决了,注意事项:

  1. mapper方法无返回值

  2. 必须用map接受procedure返回值, 不能用多变量的形式,比如如下声明是错误的

public void test(@Param("input")int input, @Param("output")Integer output);

代码演示, mapper:

    @Select(value = "{call ptest( #{input, mode=IN, jdbcType=INTEGER}, #{output, mode=OUT, jdbcType=VARCHAR} )}")
    @Options(statementType = StatementType.CALLABLE)
    public void test(Map map);

代码演示, mapper client:

    public void test( int xxx){
        Map map = new Hashtable();
        map.put("input", 1);
        map.put("output", "-");
        procDao.test(map);
        logger.info("o2 , " + map.get("output"));  //binggo!!
    }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进