打赏

Beego代码自动生成

beego 代码自动生成

1.bee api用法

usage: bee api [appname]

create an api application base on beego framework

bee api [appname] [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/
test]
    -tables: a list of table names separated by ',', default is empty, indicating all tables
    -driver: [mysql | postgres | sqlite], the default is mysql
    -conn:   the connection string used by the driver, the default is ''
             e.g. for mysql:    root:@tcp(127.0.0.1:3306)/test
             e.g. for postgres: postgres://postgres:postgres@127.0.0.1:5432/postgres

2.生成代码

bee api hello -conn=root:root@tcp(127.0.0.1:3306)/test

3.运行

bee run -downdoc=true -gendoc=true

4.Swagger API文档

http://127.0.0.1:8080/swagger/

Bee generate用法

1.bee generate语法

USAGE
  bee generate [command]

OPTIONS
  -conn
      Connection string used by the SQLDriver to connect to a database instance.
  
  -ddl
      Generate DDL Migration
  
  -driver
      Database SQLDriver. Either mysql, postgres or sqlite.
  
  -fields
      List of table Fields.
  
  -level
      Either 1, 2 or 3. i.e. 1=models; 2=models and controllers; 3=models, controllers and routers.
  
  -tables
      List of table names separated by a comma.
  
DESCRIPTION
  ▶ To scaffold out your entire application:

     $ bee generate scaffold [scaffoldname] [-fields="title:string,body:text"] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"]

  ▶ To generate a Model based on fields:

     $ bee generate model [modelname] [-fields="name:type"]

  ▶ To generate a controller:

     $ bee generate controller [controllerfile]

  ▶ To generate a CRUD view:

     $ bee generate view [viewpath]

  ▶ To generate a migration file for making database schema updates:

     $ bee generate migration [migrationfile] [-fields="name:type"]

  ▶ To generate swagger doc file:

     $ bee generate docs

  ▶ To generate a test case:

     $ bee generate test [routerfile]

  ▶ To generate appcode based on an existing database:

     $ bee generate appcode [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-level=3]

2.使用示例

bee generate scaffold user -fields-"id:int,name:string,gender:int,age:int" -driver=mysql -conn="root:123456@tcp(127.0.0.1:3306)/beego"

posted @ 2020-05-13 09:16  苍山落暮  阅读(1560)  评论(0编辑  收藏  举报