sql:
CREATE DEFINER=`root`@`%` PROCEDURE `updateAccount`(IN u_accountid varchar(50),IN u_userid VARCHAR(50), IN u_money decimal(10,0)) BEGIN
DECLARE from_account_balance decimal(10); DECLARE status_ int(2); START TRANSACTION;
SELECT balance INTO from_account_balance FROM t_account WHERE uuid = u_accountid FOR UPDATE; IF from_account_balance>=u_money THEN UPDATE t_account SET balance = balance - u_money , update_time = sysdate() WHERE uuid = u_accountid; UPDATE sys_user SET role = role + u_money WHERE uuid = u_userid; COMMIT;
SET status_=1; ELSE ROLLBACK; SET status_=0; END IF;
SELECT status_; END
mapper.xml
<select id="updateAccount" resultType="net.sf.json.JSONObject" parameterType="net.sf.json.JSONObject" statementType="CALLABLE"> {call updateAccount(#{u_accountid,mode=IN},#{u_userid,mode=IN},#{u_money,mode=IN})} </select>mapper.java
JSONObject updateAccount(JSONObject jsonObject);