1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| [root@localhost ~]# yum install mariadb-server -y [root@localhost ~]# systemctl start mariadb [root@localhost ~]# systemctl enable mariadb [root@localhost ~]# mysql -u root -p
MariaDB [(none)]> create database imooc; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> use imooc; MariaDB [imooc]> CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL DEFAULT '', `gender` tinyint(4) NOT NULL DEFAULT '0', `age` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.00 sec)
MariaDB [imooc]> INSERT INTO user (name,gender,age) values('zhangsan',1,21); Query OK, 1 row affected (0.00 sec) MariaDB [imooc]> INSERT INTO user (name,gender,age) values('lisi',0,22); Query OK, 1 row affected (0.01 sec) MariaDB [imooc]> INSERT INTO user (name,gender,age) values('wangwu',1,20); Query OK, 1 row affected (0.00 sec)
MariaDB [imooc]> select * from user; +----+----------+--------+-----+ | id | name | gender | age | +----+----------+--------+-----+ | 1 | zhangsan | 1 | 21 | | 2 | lisi | 0 | 22 | | 3 | wangwu | 1 | 20 | +----+----------+--------+-----+ 3 rows in set (0.00 sec)
生成代码 yujiangdeMBP-13:imooc yujiang$ bee generate scaffold user -fields="id:int64,name:string,gender:int,age:int" -driver=mysql -conn="root:@tcp(192.168.56.101:3306)/imooc" ______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /| __/| __/ \____/ \___| \___| v1.10.0 2018/10/28 19:30:25 INFO ▶ 0001 Do you want to create a 'user' model? [Yes|No] Yes 2018/10/28 19:31:34 INFO ▶ 0002 Using 'User' as model name 2018/10/28 19:31:34 INFO ▶ 0003 Using 'models' as package name create /Users/yujiang/go/src/imooc/models/user.go 2018/10/28 19:31:34 INFO ▶ 0004 Do you want to create a 'user' controller? [Yes|No] Yes 2018/10/28 19:31:43 INFO ▶ 0005 Using 'User' as controller name 2018/10/28 19:31:43 INFO ▶ 0006 Using 'controllers' as package name 2018/10/28 19:31:43 INFO ▶ 0007 Using matching model 'User' create /Users/yujiang/go/src/imooc/controllers/user.go 2018/10/28 19:31:43 INFO ▶ 0008 Do you want to create views for this 'user' resource? [Yes|No] Yes 2018/10/28 19:31:52 INFO ▶ 0009 Generating view... create /Users/yujiang/go/src/imooc/views/user/index.tpl create /Users/yujiang/go/src/imooc/views/user/show.tpl create /Users/yujiang/go/src/imooc/views/user/create.tpl create /Users/yujiang/go/src/imooc/views/user/edit.tpl 2018/10/28 19:31:52 INFO ▶ 0010 Do you want to create a 'user' migration and schema for this resource? [Yes|No] No 2018/10/28 19:32:11 INFO ▶ 0011 Do you want to migrate the database? [Yes|No] No 2018/10/28 19:32:13 SUCCESS ▶ 0012 All done! Don't forget to add beego.Router("/user" ,&controllers.UserController{}) to routers/route.go
2018/10/28 19:32:13 SUCCESS ▶ 0013 Scaffold successfully generated!
yujiangdeMBP-13:imooc yujiang$ tree . ├── conf │ └── app.conf ├── controllers │ ├── default.go │ └── user.go ├── imooc ├── main.go ├── models │ └── user.go ├── routers │ └── router.go ├── static │ ├── css │ ├── img │ └── js │ └── reload.min.js ├── tests │ └── default_test.go └── views ├── index.tpl └── user ├── create.tpl ├── edit.tpl ├── index.tpl └── show.tpl
11 directories, 14 files
|