码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis使用存储过程

时间:2020-03-12 18:33:29      阅读:45      评论:0      收藏:0      [点我收藏+]

标签:oca   sql   sel   java   print   getc   HERE   pre   statement   

mybatis使用存储过程

  • 创建存储过程

    CREATE DEFINER=`root`@`localhost` PROCEDURE `select_user_count`(out userCount INTEGER,OUT postCount INTEGER)
    BEGIN
      #Routine body goes here...
      SELECT count(*) as userCount from tb_sys_user into userCount;
      SELECT count(*) as postCount from tb_posts_post into postCount;
    END
  • 创建对象

    public class CountVo implements Serializable {
        private static final long serialVersionUID = 1481563278090175522L;
        private Integer userCount;
        private Integer postCount;
        //toString,get,set........
    }
  • 注解使用(不可设置数据为只读,不然out会报错的)

@Select({"call select_user_count(#{userCount,mode=OUT,jdbcType=INTEGER},#{postCount,mode=OUT,jdbcType=INTEGER})"})
    @Options(statementType = StatementType.CALLABLE)
    void getCount(CountVo countVo);
  • xml调用

    <select id="getCount" parameterType="com.base.CountVo" statementType="CALLABLE">
          {call select_user_count(
          #{userCount,mode=OUT,jdbcType=INTEGER},
          #{postCount,mode=OUT,jdbcType=INTEGER})}
    </select>
  • service层调用

    CountVo countVo = new CountVo();
    tbSysUserMapper.getCount(countVo);
    System.out.println(countVo.toString());

mybatis使用存储过程

标签:oca   sql   sel   java   print   getc   HERE   pre   statement   

原文地址:https://www.cnblogs.com/RitualYang/p/12470758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!