網站首頁 編程語言 正文
兩個跳轉語法
第一個參數是請求路徑,第二個參數是http狀態碼。
c.Redirect("/login",400) //重定向 c.TplName = "login.html"
模型創建
設置主鍵 `pk`
設置自增 `auto`
注意:當Field類型為int,int32,int64,uint,uint32,uint64時,可以設置字段為自增健,當模型定義中沒有主鍵時,符合上述類型且名稱為Id的Field將視為自增健。
設置默認值 ?`default(1111)`
設置長長度 ?`orm:size(100)`
設置允許為空 ?`null`,數據庫默認是非空,設置null后可變成`ALLOW NULL`
設置唯一 ?`orm:"unique"`
設置浮點數精度 ?`orm:"digits(12);decimals(4)"` //總共12位,四位是小數
設置時間 ?`orm:"auto_now_add;type(datetime)"`
?? ??? ??? ??? ? `orm:"auto_now;type(date)"`
注意:
auto_now 每次model保存時都會對時間自動更新
auto_now_add 第一次保存時才設置時間
設置時間的格式:type
# 案例 type User struct { beego.Controller Id int `orm:"pk;auto"` //主鍵且自增 Name string `orm:"size(20)"` //長度20 CreateTime time.Time Count int `orm:"defaule(0);null"` //默認為0,可以為空 }
獲取post請求傳過來的值
獲取字符串
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:錯誤信息 defer f.Close() if err != nil{ beego.Info("上傳文件失敗") }else { c.SaveToFile("file_name","./staic/img/"+h.Filename) }
Html
就是別忘記在你的 form 表單中增加這個屬性 enctype="multipart/form-data",否則你的瀏覽器不會傳輸你的上傳文件。
<!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="注冊">
</form>
</div>
</div>
</body>
</html>
獲取文件后綴
fileext := path.Ext(h.Filename)
orm查詢表所有數據
var table_lis []models.User _,err := o.QueryTable("User").All(&table_lis) if err !=nil{ beego.Info("查詢文章出錯") return } beego.Info(table_lis)
前端循環語法
c.Data["table_lis"] = table_lis //業務邏輯傳過來的值 {{range .table_lis}} //循環訪問 <tr> <td>{{.Name}}</td> <td>{{.PassWord}}</td> </tr> {{end}}
前端格式化時間
<td>{{.time.Format "2006-01-02"}}</td> //格式化時間
前端url傳值方式
<td><a href="/addAritcle?id={{.Id}}" ></a></td>
原文鏈接:https://www.cnblogs.com/guyouyin123/p/14082063.html
相關推薦
- 2023-04-18 獲取Android簽名MD5的方式實例詳解_Android
- 2023-07-04 Guava 之 EventBus
- 2022-04-24 Android掛斷電話最新實現方法_Android
- 2022-12-09 Flutter?Widgets?MediaQuery控件屏幕信息適配_IOS
- 2022-11-23 StoneDB主從配置及切換實踐方案_數據庫其它
- 2023-08-01 elementui自定義Slider樣式
- 2022-01-18 正則——16進制顏色
- 2022-05-13 Django-認證-權限控制-節流-分頁-過濾
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支