mybatis调用 存储过程方法简单demo

来源:互联网 发布:mac装双系统 编辑:程序博客网 时间:2024/05/21 20:43

以下是一次简单 的存储过程调用并且在sql中使用行级锁,

本例仅为演示,实际操作请尽量使用spring事务进行管理


Mapper接口类

public interface ???Mapper {public void getCheckOutLock(CheckOutProduce checkOutProduce);}

存储过程

CREATE PROCEDURE get_check_out_lock(IN `receptionId` bigint,OUT `result` int) BEGIN#Routine body goes here...DECLARE record_version int ;#开启事务START TRANSACTION;#加入排他锁SELECT version from reception where reception_id = receptionId INTO record_version for update;#该条记录未被锁定if(record_version = 0) then set result = 1;UPDATE reception SET version = 1 where reception_id = receptionId ;else set result = 0;end if;COMMIT;END

mapper.xml文件写法
<select id="getCheckOutLock" parameterType="com.kzhotel.pojo.CheckOutProduce"     statementType="CALLABLE" resultType="com.kzhotel.pojo.CheckOutProduce">    {call get_check_out_lock (#{receptionId,jdbcType=INTEGER,mode=IN},#{result,jdbcType=INTEGER,mode=OUT})}  </select>
实体类定义

package com.kzhotel.pojo;public class CheckOutProduce {private Long receptionId;private Integer result;public Long getReceptionId() {return receptionId;}public void setReceptionId(Long receptionId) {this.receptionId = receptionId;}public Integer getResult() {return result;}public void setResult(Integer result) {this.result = result;}}


原创粉丝点击