# Get方法 查询单条数据使用Get方法,在调用Get方法时需要传入一个对应结构体的指针,同时结构体中的非空field自动成为查询的条件和前面的方法条件组合在一起查询。 如: 1) 根据Id或者name来获得单条数据: ~~~ has, err := engine.Get(&user) // SELECT * FROM user LIMIT 1 has, err := engine.Where("name = ?", name).Desc("id").Get(&user) // SELECT * FROM user WHERE name = ? ORDER BY id DESC LIMIT 1 var name string has, err := engine.Where("id = ?", id).Cols("name").Get(&name) // SELECT name FROM user WHERE id = ? var id int64 has, err := engine.Where("name = ?", name).Cols("id").Get(&id) // SELECT id FROM user WHERE name = ? var valuesMap = make(map[string]string) has, err := engine.Where("id = ?", id).Get(&valuesMap) // SELECT * FROM user WHERE id = ? var valuesSlice = make([]interface{}, len(cols)) has, err := engine.Where("id = ?", id).Cols(cols...).Get(&valuesSlice) // SELECT col1, col2, col3 FROM user WHERE id = ? ~~~ 2) 根据Where来获得单条数据: ~~~ user := new(User) has, err := engine.Where("name=?", "xlw").Get(user) ~~~ 3) 根据user结构体中已有的非空数据来获得单条数据: ~~~ user := &User{Id:1} has, err := engine.Get(user) ~~~ 或者其它条件 ~~~ user := &User{Name:"xlw"} has, err := engine.Get(user) ~~~ 返回的结果为两个参数,一个has为该条记录是否存在,第二个参数err为是否有错误。不管err是否为nil,has都有可能为true或者false。