5.7 事务

    1. // 本例仅为示例, 并未严格考虑账户状态等业务逻辑
    2. @Before(Tx.class)
    3. public void trans_demo() {
    4. // 获取转账金额
    5. Integer transAmount = getParaToInt("transAmount");
    6. // 获取转出账户id
    7. Integer fromAccountId = getParaToInt("fromAccountId");
    8. Integer toAccountId = getParaToInt("toAccountId");
    9. // 转出操作
    10. Db.update("update account set cash = cash - ? where id = ?",
    11. transAmount, fromAccountId);
    12. // 转入操作
    13. Db.update("update account set cash = cash + ? where id = ?",
    14. transAmount, toAccountId);
    15. }
    1. @TxConfig("otherConfigName")
      (Tx.class)
      public void doIt() {

      }

    2、Db.tx 事务

    1. Db.tx(new IAtom() {
    2. public boolean run() throws SQLException {
    3. Db.update("update t1 set f1 = ?", 123);
    4. Db.update("update t2 set f2 = ?", 456);
    5. return true;
    6. });