In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the go language beego framework web development syntax of the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you have something to gain after reading this article, let's take a look at it.
Two jump syntax
The first parameter is the request path, and the second parameter is the http status code.
C.Redirect ("/ login", 400) / / Redirect c.TplName = "login.html" model creation
Set the primary key `pk`
Set self-increment `auto`
Note: when the Field type is int,int32,int64,uint,uint32,uint64, you can set the field to self-augmentation, and when there is no primary key in the model definition, the Field with the name Id that matches the above type will be regarded as self-augmentation.
Set the default value `default (1111) `
Set the long length `orm:size (100) `
The setting is allowed to be empty `null`, and the database is not empty by default. After setting null, it can be changed to `null`.
Set unique `orm: "unique" `
Set floating point precision `orm: "digits (12); decimals (4)" `/ / A total of 12 digits, with four decimal places
Set time `orm: "auto_now_add;type (datetime)" `
`orm: "auto_now;type (date)" `
Note:
Auto_now automatically updates the time every time model is saved.
Auto_now_add only sets the time when it is saved for the first time
Format the time: type
# case type User struct {beego.Controller Id int `orm: "pk;auto" `/ / primary key and add Name string `orm: "size (20)"` / / length 20 CreateTime time.Time Count int `orm: "defaule (0) Null "`/ / defaults to 0 You can get the string c.GetString ("userName") / / the string func (c*MainController) AddAritcle () {c.Data ["name"] = c.GetString ("userName") c.Data ["pwd"] = c.GetString ("passwd") beego.Info ("user name:", c.Data ["name"]) beego.Info ("password") C.Data ["pwd"]) c.TplName = "success.html"} get the file fjinh Err: = c.GetFile ("file_name") / / get file / / f: file handle / / h: file information / / err: error message defer f.Close () if err! = nil {beego.Info ("file upload failed")} else {c.SaveToFile ("file_name", ". / staic/img/" + h.Filename)}
Html
Just don't forget to add this attribute enctype= "multipart/form-data" to your form form, otherwise your browser will not transfer your uploaded files.
Login user name:
Password:
Get the file suffix fileext: = path.Ext (h.Filename) orm query table all data var table_lis [] models.User_ Err: = o.QueryTable ("User"). All (& table_lis) if err! = nil {beego.Info ("query article error") return} beego.Info (table_lis) Front end Loop Syntax c.Data ["table_lis"] = table_lis / / the value passed by the business logic {{range .table _ lis}} / iterates to the {{.Name}} {{end}} front-end format Transformation time {{. Time.Format "2006-01-02"}} / / format time front-end url values are all the contents of the article "what is the go language beego Framework web Development Syntax?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.