-
Notifications
You must be signed in to change notification settings - Fork 25
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
5 changed files
with
59 additions
and
31 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
4 changes: 4 additions & 0 deletions
4
...-test/src/main/java/gaarason/database/spring/boot/starter/mybatis/test/TestException.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,4 @@ | ||
package gaarason.database.spring.boot.starter.mybatis.test; | ||
|
||
public class TestException extends Exception { | ||
} |
31 changes: 31 additions & 0 deletions
31
...st/src/main/java/gaarason/database/spring/boot/starter/mybatis/test/service/TService.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,31 @@ | ||
package gaarason.database.spring.boot.starter.mybatis.test.service; | ||
|
||
import gaarason.database.eloquent.GeneralModel; | ||
import gaarason.database.spring.boot.starter.mybatis.test.TestException; | ||
import gaarason.database.spring.boot.starter.mybatis.test.mybatis.mapper.StudentMapper; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.annotation.Resource; | ||
|
||
@Service | ||
public class TService { | ||
|
||
@Resource | ||
private StudentMapper studentMapper; | ||
|
||
@Resource | ||
private GeneralModel generalModel; | ||
|
||
@Transactional( transactionManager="gaarasonTransactionManager", rollbackFor = TestException.class) | ||
public void doSomething(int id, int age) throws TestException { | ||
|
||
studentMapper.updateAgeById(id, age); | ||
|
||
Object ageBySelect = generalModel.newQuery().from("student").where("id", id).firstOrFail().toMap().get("age"); | ||
|
||
System.out.println("通过mybatis更新后, age : " + ageBySelect); | ||
|
||
throw new TestException(); | ||
} | ||
} |
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