beegoDemo/beego_demo1/models/orm1.go

36 lines
813 B
Go
Raw Normal View History

2021-07-13 17:33:56 +08:00
package models
import "github.com/astaxie/beego/orm"
/**
代表忽略 `orm:"-"`
*/
type User struct {
Id int `json:"id" orm:"pk"`
Name string `json:"name" orm:"column(name)"`
Age int `json:"age" orm:"column(age)"`
Addr string `json:"addr" orm:"column(addr)"`
Class string `json:"clazz" orm:"column(clazz)"`
}
/**
1默认表面以大写字母分割中间加下划线,首字母的大写只转换为小写前面不加下划线
SysUser -> sys_user
DBUser -> d_b_user
Sys_User -> sys__user
重写表名
*/
//func (u * User) TableName() string {
// return "sys_user"
//}
func init() {
//需要放在init下 注册models
orm.RegisterModel(new(User))
/*
//前缀
orm.RegisterModelWithPrefix("sys",new(User))
//后缀
orm.RegisterModelWithSuffix("sys",new(User))
*/
}