[TOC] ## 方法 ``` BeforeInsert() BeforeUpdate() BeforeDelete() AfterInsert() AfterUpdate() AfterDelete() AfterSet(name string, cell xorm.Cell) BeforeSet(name string, cell xorm.Cell) ``` ## 临时替换操作 临时执行某个方法之前执行 ``` before := func(bean interface{}){ fmt.Println("before", bean) } engine.Before(before).Insert(&obj) //engine.After(after).Insert(&obj) ``` ## 执行 执行插入操作 ``` func (s *SysAdmin) BeforeInsert() { s.UserLogin = "user_idcp" } engine.Insert(sysAdmin) ``` 执行get 或find 操作 ``` func (s *SysAdmin) AfterSet(name string, cell xorm.Cell) { s.UserLogin = "aaaaaaaaaaaaa" //获取前修改值 fmt.Println("name :", name) fmt.Println("cell", *cell) } sysAdmin.UserId = "7" engine.Get(sysAdmin) ```