We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
example/ 文件夹里面 有例子。 文档网站里面也有文档。 2种办法, 第一种是声明式事务,和java spring的类似,有传播行为
type TestService struct { exampleActivityMapper *ExampleActivityMapper //服务包含一个mapper操作数据库,类似java spring mvc //类似拷贝spring MVC的声明式事务注解 //rollback:回滚操作为error类型(你也可以自定义实现了builtin.error接口的自定义struct,框架会把自定义的error类型转换为string,检查是否包含,是则回滚 //tx:"" 开启事务,`tx:"PROPAGATION_REQUIRED,error"` 指定传播行为为REQUIRED(默认REQUIRED)) UpdateName func(id string, name string) error `tx:"" rollback:"error"` UpdateRemark func(id string, remark string) error `tx:"" rollback:"error"` }
第二种本地事务,直接使用session.begin , close 等等方法
//本地事务使用例子 func Test_local_Transation(t *testing.T) { if MysqlUri == "" || MysqlUri == "*" { fmt.Println("no database url define in Example_config.go , you must set the mysql link!") return } //使用事务 var session, err = exampleActivityMapper.SessionSupport.NewSession() if err != nil { t.Fatal(err) } session.Begin(nil) //开启事务 var activityBean = Activity{ Id: "170", Name: "rs168-8", } var updateNum, e = exampleActivityMapper.UpdateById(&session, activityBean) //sessionId 有值则使用已经创建的session,否则新建一个session fmt.Println("updateNum=", updateNum) if e != nil { panic(e) } session.Commit() //提交事务 session.Close() //关闭事务 }
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: