zoukankan      html  css  js  c++  java
  • mybatis使用存储过程

    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());
      
  • 相关阅读:
    C++ 虚函数表解析
    C#编写简单的聊天程序
    c#事件与委托
    c#文本控件实现换行
    docker 详细安装及问题排查
    hadoop命令行
    Spark中的多线程并发处理
    CDH6.1.0离线安装——笔记
    linux 常用命令
    Rsync 恢复 libselinux.SO.1
  • 原文地址:https://www.cnblogs.com/RitualYang/p/12470758.html
Copyright © 2011-2022 走看看