JFinal

添加事务方式
    一种是添加在DAO中(未验证)
        boolean succeed = Db.tx(new IAtom(){
              public boolean run()  {
                int count = Db.update("update account set cash = cash - ? where id = ?", 100, 123);
                int count2 = Db.update("update account set cash = cash + ? where id = ?", 100, 456);
                return count == 1 && count2 == 1;
              }});

     一种是添加在Action中(已验证)
        @Before(Tx.class)
        public void xxxAction(){
            try {
                // 业务逻辑
            } catch (Exception e) {
                renderErrorJson("操作失败");// 自定义render
                throw new NestedTransactionHelpException("操作失败,回滚");
            }
            renderSuccessJson("操作成功"); // 自定义render
        }

你可能感兴趣的:(JFinal)