package main
import (
_ "crud_beego/routers" //自动注册路由
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)
const (
DRIVER_NAME = "mysql"
DATA_SOURCE = "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Asia%2FShanghai"
MAX_IDLE_CONN = 5
MAX_OPEN_CONN = 30
)
type User struct {
Id int
Name string
Email string
Age int
isActive bool
}
func (u *User) TableName() string {
return "t_user"
}
func registerDB() {
orm.Debug = true
orm.RegisterDataBase("default", DRIVER_NAME, DATA_SOURCE, MAX_IDLE_CONN, MAX_OPEN_CONN)
orm.RegisterModel(new(User))
}
func (this User) ToString() string {
return fmt.Sprintf("Id:%d\tName:%s\tEmail:%s\tAge:%d\tisActive:%v", this.Id, this.Name, this.Email, this.Age, this.is
golang学习之beego增删改查代码实现
最新推荐文章于 2022-04-23 01:15:25 发布
本文介绍了如何使用Golang的Beego框架进行基本的增删改查(CRUD)操作,包括创建模型、配置路由、执行SQL语句等步骤,详细讲解了每个环节的关键代码,为Golang初学者提供了实用的Web开发指南。
摘要由CSDN通过智能技术生成