mybatis调用 存储过程方法简单demo
2017-11-17 14:44
531 查看
以下是一次简单 的存储过程调用并且在sql中使用行级锁,
本例仅为演示,实际操作请尽量使用spring事务进行管理
Mapper接口类
存储过程
mapper.xml文件写法
本例仅为演示,实际操作请尽量使用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; } }
相关文章推荐
- C#调用存储过程的方法,和简单存储过程创建的方法实例。【转载】为入门的朋友引路,大家互相学习。
- Mybatis调用数据库的存储过程和方法
- Mybatis调用数据库的存储过程和方法
- Python简单调用MySQL存储过程并获得返回值的方法
- Mybatis调用MySQL存储过程的简单实现
- Python简单调用MySQL存储过程并获得返回值的方法
- Oracle数据库连接与调用简单的存储过程
- 存储过程中简单事务书写方法
- Mybatis 存储过程调用
- Java对存储过程的调用方法
- php调用mysql存储过程和函数的方法
- sqlserver 2008 存储过程调用存储过程或方法
- mybatis 调用 oracle 返回结果集 存储过程
- C#调用mysql存储过程方法
- 存储过程output参数_数据库调用_C#_NET调用简单CODE
- 通用存储过程调用方法
- 存储过程和SQL语句比较及存储过程在C#中调用方法
- 用pl/sql自己编写简单的存储过程及jdbc调用存储过程
- 简单搞一下 System.Data.OracleClient调用带blob、clob等大字段类型参数的存储过程!
- Sql Server 中带参数的存储过程及在Reporting Services 中的调用方法