<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                如果現在我們要刪除person表中id為5的記錄,但是在PersonServiceBean類的delete()方法中,人為地拋出一個運行時異常,如下 ~~~ public void delete(Integer personid) { jdbcTemplate.update("delete from person where id=?", new Object[]{personid}, new int[]{java.sql.Types.INTEGER}); throw new RuntimeException("運行期異常"); } ~~~ 此時測試PersonServiceTest類中的delete()方法: ~~~ @Test public void delete() { personService.delete(5); } ~~~ 會發現Eclipse控制臺打印出一個異常,立馬查看person表,發現id為5的記錄沒有刪除掉,這就說明了Spring容器默認情況下對運行時異常,它會進行事務的回滾。 如果在PersonServiceBean類的delete()方法中,人為地拋出一個檢查時異常,如下: ~~~ public void delete(Integer personid) throws Exception { jdbcTemplate.update("delete from person where id=?", new Object[]{personid}, new int[]{java.sql.Types.INTEGER}); throw new Exception("檢查時異常"); } ~~~ 為了不報錯,我們還須將PersonService接口中的delete()方法簽名修改為: ~~~ /** * 刪除指定id的person */ public void delete(Integer personid) throws Exception; ~~~ 此時測試PersonServiceTest類中的delete()方法 ~~~ @Test public void delete() { try { personService.delete(5); } catch (Exception e) { e.printStackTrace(); } } ~~~ 會發現控制臺打印出一個異常,立馬查看person表,發現id為5的記錄被刪除掉,這就說明了如果Spring容器碰到的是用戶異常,如檢查時異常(checked exception),這時事務就不會回滾。 當然我們也可改變這種規則: * 當Spring容器碰到用戶異常——如檢查時異常(checked exception)時,讓事務回滾。 那到底該怎么辦呢?此時就需要用到事務的rollbackFor屬性了。我們將PersonServiceBean類的delete()方法修改為: ~~~ @Transactional(rollbackFor=Exception.class) public void delete(Integer personid) throws Exception { jdbcTemplate.update("delete from person where id=?", new Object[]{personid}, new int[]{java.sql.Types.INTEGER}); throw new Exception("檢查時異常"); } ~~~ 此時測試PersonServiceTest類中的delete()方法: ~~~ @Test public void delete() { try { personService.delete(4); } catch (Exception e) { e.printStackTrace(); } } ~~~ 會發現控制臺打印出一個異常,立馬查看person表,發現id為4的記錄沒有被刪除掉。 * 當Spring容器碰到運行時異常時,不讓它進行事務的回滾,而是提交事務。 那到底該怎么辦呢?此時就需要用到事務的rollbackFor屬性了。我們將PersonServiceBean類的delete()方法修改為: ~~~ @Transactional(noRollbackFor=RuntimeException.class) public void delete(Integer personid) throws Exception { jdbcTemplate.update("delete from person where id=?", new Object[]{personid}, new int[]{java.sql.Types.INTEGER}); throw new RuntimeException("運行期異常"); } ~~~ 此時測試PersonServiceTest類中的delete()方法, 會發現Eclipse控制臺打印出一個異常,立馬查看person表,發現id為4的記錄已經被刪除掉了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看