存储过程还不会写的同学可以参考我另一篇文章:https://www.cnblogs.com/liuboyuan/p/9375882.html

网上已经有很多用mybatis调用的教程了,但是大部分是xml方式调用,最近项目中用mybatis plus,没有xml配置文件。本次分享下用@Select注解方式调用。

创建存储过程(语法oracle)

create or replace procedure test(name in  varchar,gender out varchar)
as
begin
if name = 'xiaoming' then gender := 'man';
else gender := 'woman';
end if;
end;

测试一下

declare
name varchar(16);
gender varchar(16);
begin
name:='xiaoming';
test(name,gender);
dbms_output.put_line(gender); --控制台打印man
end;

如果mybatis使用的连接数据库用户权限比较低,还需要授权才能执行

grant execute on 库名.存储过程名称 to 用户; --别忘了给用户授权

准备测试pojo

import lombok.*;

@Data
@NoArgsConstructor
@ToString
public class People {
private String name;
private String gender;
}

mapper的写法

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType; @Mapper
public interface TestMapper {
@Select("{call 库名.test(#{name,jdbcType=VARCHAR,mode=IN},#{gender,jdbcType=VARCHAR,mode=OUT})}")
@Options(statementType = StatementType.CALLABLE)
void getGengder(People people);
}

测试类

    @Resource
private TestMapper testMapper; @Test
public void test() {
People people = new People();
people.setName("xiaoming");
testMapper.getGengder(people);
System.out.println(people); //(name=xiaoming,gender=man)
}

最新文章

  1. re模块详解
  2. ruby on rails validates uniqueness
  3. (转) C++中基类和派生类之间的同名函数的重载问题
  4. shell script 学习笔记-----shell变量
  5. C使用FILE指针文件操作
  6. 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)
  7. Django生命周期 URL ----> CBV 源码解析-------------- 及rest_framework APIView 源码流程解析
  8. 类 Arrays StringBuilder 跟 StringBuffer 的异同 SimpleDateFormat
  9. python基础(16)私有类,类,类变量
  10. es6 语法 (正则扩展)
  11. 强化学习(三)—— 时序差分法(SARSA和Q-Learning)
  12. 网络编程基础【day09】:socketserver使用(九)
  13. codeforces510B
  14. 自学Zabbix3.12.5-动作Action-Condition配置
  15. 每天学点Linux命令之grep 和 wc命令
  16. Win10系列:VC++调用自定义组件1
  17. Python2.7-datetime
  18. unittest参数化
  19. java企业级开发的实质就是前台后台如何交互的-各个对象之间如何交互,通信的-程序执行的流程是怎样的
  20. python轻量级ORM---peewee

热门文章

  1. springboot 2.x相关配置
  2. 用idea将本地项目提交到gitlab上
  3. Update Vim to 8.0 in Ubuntu
  4. iview下拉树组件
  5. php-fpm.conf详细解析篇
  6. 6.zabbix微信告警3.2
  7. (转)使用OpenGL ES显示图像
  8. 国际C 语言乱码大赛(IOCCC )
  9. MySQL if,ifnull,nullif 函数
  10. 用processing画李萨如曲线