package model import ( "context" "fmt" "github.com/jmoiron/sqlx" ) type KillaraCustomerModel struct { // fields ... db *sqlx.DB TableName string // 表名 } func (m *KillaraCustomerModel) Find(ctx context.Context) (result []*KillaraCustomer, err error) { var customer []*KillaraCustomer err = m.db.SelectContext(ctx, customer, fmt.Sprintf("select * from %s", m.TableName)) if err != nil { return nil, err } return customer, nil }