更新指定字段


  1. dao := NewDbtestDao()
  2. param := torm.CastToParamIn([]int{1})
  3. lists, err := dao.Get(param)
  4. if err != nil {
  5. return err
  6. }
  7. if len(lists) > 0 {
  8. row := lists[0]
  9. row.Param1 = 100
  10. row.Param2 = "update1"
  11. row.Param3 = "update1"
  12. affect, err := dao.UpdateCols(&row, "param2", "param3")
  13. }
  • UpdateCols(&row, “param2”, “param3”)方法传入不定数量参数,参数为指定更新字段,需为表实际字段名