-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...g-boot/101-jdbctemplate-transaction/src/main/java/com/git/hui/boot/jdbc/api/TransApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.git.hui.boot.jdbc.api; | ||
|
||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* @author yihui | ||
* @date 21/5/24 | ||
*/ | ||
public interface TransApi { | ||
|
||
@Transactional(rollbackFor = Exception.class) | ||
boolean update(int id); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...ot/101-jdbctemplate-transaction/src/main/java/com/git/hui/boot/jdbc/api/TransApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.git.hui.boot.jdbc.api; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author yihui | ||
* @date 21/5/24 | ||
*/ | ||
@Service | ||
public class TransApiImpl implements TransApi { | ||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@Override | ||
public boolean update(int id) { | ||
String sql = "replace into money (id, name, money) values (" + id + ", '事务测试', 200)"; | ||
jdbcTemplate.execute(sql); | ||
|
||
Object ans = jdbcTemplate.queryForMap("select * from money where id = 111"); | ||
System.out.println(ans); | ||
|
||
throw new RuntimeException("事务回滚"); | ||
} | ||
} |