網(wǎng)站首頁 編程語言 正文
兩個(gè)跳轉(zhuǎn)語法
第一個(gè)參數(shù)是請(qǐng)求路徑,第二個(gè)參數(shù)是http狀態(tài)碼。
c.Redirect("/login",400) //重定向 c.TplName = "login.html"
模型創(chuàng)建
設(shè)置主鍵 `pk`
設(shè)置自增 `auto`
注意:當(dāng)Field類型為int,int32,int64,uint,uint32,uint64時(shí),可以設(shè)置字段為自增健,當(dāng)模型定義中沒有主鍵時(shí),符合上述類型且名稱為Id的Field將視為自增健。
設(shè)置默認(rèn)值 ?`default(1111)`
設(shè)置長(zhǎng)長(zhǎng)度 ?`orm:size(100)`
設(shè)置允許為空 ?`null`,數(shù)據(jù)庫默認(rèn)是非空,設(shè)置null后可變成`ALLOW NULL`
設(shè)置唯一 ?`orm:"unique"`
設(shè)置浮點(diǎn)數(shù)精度 ?`orm:"digits(12);decimals(4)"` //總共12位,四位是小數(shù)
設(shè)置時(shí)間 ?`orm:"auto_now_add;type(datetime)"`
?? ??? ??? ??? ? `orm:"auto_now;type(date)"`
注意:
auto_now 每次model保存時(shí)都會(huì)對(duì)時(shí)間自動(dòng)更新
auto_now_add 第一次保存時(shí)才設(shè)置時(shí)間
設(shè)置時(shí)間的格式:type
# 案例 type User struct { beego.Controller Id int `orm:"pk;auto"` //主鍵且自增 Name string `orm:"size(20)"` //長(zhǎng)度20 CreateTime time.Time Count int `orm:"defaule(0);null"` //默認(rèn)為0,可以為空 }
獲取post請(qǐng)求傳過來的值
獲取字符串
c.GetString("userName") //獲取字符串 func (c*MainController) AddAritcle() { c.Data["name"] = c.GetString("userName") c.Data["pwd"] = c.GetString("passwd") beego.Info("用戶名:",c.Data["name"]) beego.Info("密碼",c.Data["pwd"]) c.TplName = "success.html" }
獲取文件
f,h,err :=c.GetFile("file_name") //獲取文件 //f:文件句柄 //h:文件信息 //err:錯(cuò)誤信息 defer f.Close() if err != nil{ beego.Info("上傳文件失敗") }else { c.SaveToFile("file_name","./staic/img/"+h.Filename) }
Html
就是別忘記在你的 form 表單中增加這個(gè)屬性 enctype="multipart/form-data",否則你的瀏覽器不會(huì)傳輸你的上傳文件。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陸</title>
</head>
<body>
<div>
<div style="position:absolute;left:50%; top:50%;">
<form action="/addAritcle" method="post" enctype="multipart/form-data">
用戶名:<input type="text" name="userName">
<p></p> 密碼:<input type="password" name="passwd">
<input type="file" name="uploadfilename">
<p></p> <input type="submit" value="注冊(cè)">
</form>
</div>
</div>
</body>
</html>
獲取文件后綴
fileext := path.Ext(h.Filename)
orm查詢表所有數(shù)據(jù)
var table_lis []models.User _,err := o.QueryTable("User").All(&table_lis) if err !=nil{ beego.Info("查詢文章出錯(cuò)") return } beego.Info(table_lis)
前端循環(huán)語法
c.Data["table_lis"] = table_lis //業(yè)務(wù)邏輯傳過來的值 {{range .table_lis}} //循環(huán)訪問 <tr> <td>{{.Name}}</td> <td>{{.PassWord}}</td> </tr> {{end}}
前端格式化時(shí)間
<td>{{.time.Format "2006-01-02"}}</td> //格式化時(shí)間
前端url傳值方式
<td><a href="/addAritcle?id={{.Id}}" ></a></td>
原文鏈接:https://www.cnblogs.com/guyouyin123/p/14082063.html
相關(guān)推薦
- 2023-04-06 rust解決嵌套——Option類型的map和and_then方法的使用_Rust語言
- 2022-12-14 正則表達(dá)式匹配0-10的正整數(shù)以及使用細(xì)節(jié)_正則表達(dá)式
- 2022-08-03 python數(shù)據(jù)類型可變與不可變深入分析_python
- 2022-07-25 Python定時(shí)任務(wù)框架APScheduler安裝使用詳解_python
- 2022-06-06 PyTorch?device與cuda.device用法介紹_python
- 2022-07-27 C++中this指針理解及作用_C 語言
- 2022-07-31 pandas中提取DataFrame某些列的一些方法_python
- 2022-12-07 C語言程序中結(jié)構(gòu)體的內(nèi)存對(duì)齊詳解_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支