阿里规范不建议使用存储过程,当不得不使用存储过程时可以参考该教程
开始
通过搜索引擎搜索了获取返回值的 MyBatis 注解配置方式,但是都搜索不到,都是 xml 配置方式,尝试自己写出来了。
过程
首先要有一个存储过程,in,out值。
配置 mapper:
部分代码:1
2
3
4
5
6
7
8
9
10
11
12
13//mybatis 注解 调用存储过程
@Select({
"call execute_seckill(",
"#{map.seckillId,mode=IN,jdbcType=BIGINT},",
"#{map.userPhone,mode=IN,jdbcType=BIGINT},",
"#{map.killTime,mode=IN,jdbcType=TIMESTAMP},",
"#{map.result,mode=OUT,jdbcType=INTEGER});"
})
@Results({
@Result(column="result", property="result", jdbcType= JdbcType.INTEGER)
})
@Options(statementType = StatementType.CALLABLE)
void killByProcedure(@Param("map") Map map);StatementType.CALLABLE表示 存储过程- 配置 service
部分代码:
- 配置 service
1 | Map<String, Object> map = new HashMap<>(); |
通过map相对应的可以获取到result值。
总结
多动手去尝试不同的实现方式,才能提升自己的动手、思考的能力。

