mybatis调用存储过程(@Select方式)
2024-08-29 01:32:30
存储过程还不会写的同学可以参考我另一篇文章: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)
}
最新文章
- re模块详解
- ruby on rails validates uniqueness
- (转) C++中基类和派生类之间的同名函数的重载问题
- shell script 学习笔记-----shell变量
- C使用FILE指针文件操作
- 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)
- Django生命周期 URL ---->; CBV 源码解析-------------- 及rest_framework APIView 源码流程解析
- 类 Arrays StringBuilder 跟 StringBuffer 的异同 SimpleDateFormat
- python基础(16)私有类,类,类变量
- es6 语法 (正则扩展)
- 强化学习(三)—— 时序差分法(SARSA和Q-Learning)
- 网络编程基础【day09】:socketserver使用(九)
- codeforces510B
- 自学Zabbix3.12.5-动作Action-Condition配置
- 每天学点Linux命令之grep 和 wc命令
- Win10系列:VC++调用自定义组件1
- Python2.7-datetime
- unittest参数化
- java企业级开发的实质就是前台后台如何交互的-各个对象之间如何交互,通信的-程序执行的流程是怎样的
- python轻量级ORM---peewee