首页 > 技术文章 > golang sqlx查询时, struct字段冲突

-xuzhankun 2019-05-14 11:07 原文

type TA struct {

  Id int64 `db:"id"`

}

 

type TB struct {

  Id int64 `db:"id"`

}

 

type TC struct {

  TA

  TB

}

如上的sql和结构体, 当查询sql,用TC结构体封装时, 有两个id字段,  那么数据库中id的值是在TB的id中

 

如果TC的结构体是

type TC struct {

  TB

  TA

}

这样, 那么id的值就是在TA中

 

推荐阅读