项目:基于人脸识别的无卡ATM机模拟系统
在完成两个账户转账的时候,主要需要完成两个表的关联更新时(即一个账户扣钱,一个账户存钱),对我这种小白来说,通常
第一反应就是写两个sql语句,分别执行这两条语句,用web项目翻译来说就是写两个update语句然后DAO下写这两个接口,在server的同一个方法中调用这两个接口。
第二写存储过程,或者存储函数。
第三批操作,然后批量执行。
第四 也是这次纠结的然后查询出来方法,因为我突然想到plsql中都可以直接运行两条语句,那么mybatis中也应该可以,结果是果然可以。先给出答案把
只需要在jdbc:url后面跟上allowMultiQueries=true的参数
如我的jdbc:mysql://localhost:3306/xhdesing?characterEncoding=UTF-8&allowMultiQueries=true
characterEncoding 配置编码,用户防止数据库与服务器请求,防止乱码。
allowMultiQueries 配置同一标签内,用户一次执行多条语句。
allow允许
Multi多个
Queries查询
您可以跳过下面了,这里只是我艰苦的探索过程,也许还有其他的方式,希望大家评论交流,谢谢
今天纠结的实现过程
1.第一反应如下:
mapper配置文件
<mapper namespace="com.xihua.facedistinguish.dao.MenuDao">
<!-- 做减法操作 -->
<update id="transger_subtraction" parameterType="string">
update atm_card
set card_money = card_money-${money }
where card_id = '${outCard }' and save_type= '${outtype }'
</update>
<!-- 做加法操作 -->
<update id="transger_add" parameterType="string">
update atm_card
set card_money = card_money+${money }
where card_id = '${infoCard }' and save_type= '${infotype }'
</update>
</mapper>
DAO
public interface MenuDao {