Commit on jdbcTemplate or DataSource

后端 未结 5 740
天命终不由人
天命终不由人 2021-02-02 14:31

I wanted to do commit and rollback using jdbcTemplate.

My question is based on this thread

How do I commit or rollback, should I do it on jdbcTemplate like

5条回答
  •  梦如初夏
    2021-02-02 15:09

    the easiest way of managing transactions in spring is @Transactional annotation, so your code will look very simple:

    @Transactional(rollbackFor = Exception.class)
    public void doSomething(...) {
        ...
    }
    

    read more: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html

提交回复
热议问题