Post

Beego MVC

beego MVC

自动生成 controller 和 models

1
  bee generate appcode -tables="integral_acquisition" -conn="shareaio_server:shareaio@2019@tcp(47.244.225.92:9936)/shareaio_server"

controller

接口 swagger

1
2
3
4
5
6
7
8
9
10
11
12
  func (this *StatisticsController) URLMapping() {
    this.Mapping("VisitorTraffic", this.VisitorTraffic)
  }
  // @Summary 首页点赞
  // @Title 标题
  // @Description 描述
  // @Param   Authorization     header    string  true       "Authorization"
  // @Success 200 {object} models.ZDTProduct.ProductList
  // @Failure
  // @router /test [get]
  func (this *StatisticsController) VisitorTraffic() {
  }

model

一对多

  • 一对多关系 info 多个订单 Info 里面写

    1
    
    InfoOrder 		[]*InfoOrder 	`orm:"reverse(many)"` //设置一对多的反向关系
    

    OrderInfo 里面写

    1
    
    Info        	*Info 			 `orm:"rel(fk)"`  //设置一对多关系
    
  • 多对多

struct

1
2
3
  type Id struct {
    Id int64 `json:"id,omitempty"`//第一个为显示的json数据名称;第二个设置为空就不展示
  }

字段备注

1
2
3
4
5
6
7
8
9
10
  type User struct{
    Id int64 `orm:"auto;description(id)" json:"id"`
    UId int64 `orm:"size(11);description(余额支付的用户名)" json:"u_id"`
  }
  CREATE TABLE `t_user` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `u_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '余额支付的用户名',
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

view

This post is licensed under CC BY 4.0 by the author.