10-grom-05-高级查询
1. Order
1.1 简单使用
age字段降序,name字段升序(默认)
db.Order("age desc, name").Find(&users)
SELECT * FROM users ORDER BY age desc, name;
或者写成
db.Order("age desc").Order("name").Find(&users)
示例
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
type xiShu struct {
ID int64
Name string
Age int64
}
func(xiShu) TableName() string {
return "xi_shu"
}
fun
共有 0 条评论