## 1、獲取url上的參數,?后面的 :[http://127.0.0.1:8090/user/?id=111](http://127.0.0.1:8090/user/?id=111)
GetString獲取數據:
? 路由:
~~~
beego.Router("/user", &controllers_user.UserController{})
~~~
訪問路徑:http://127.0.0.1:8090/user/?id=111
獲取數據:
```
? ? ? id := c.Input().Get("id")
? ? ? id2 := c.GetString("id")
```
?
? ? ? 這種方式不行:
? ? ? ? ? id3 := c.Ctx.Input.Param(":id")
## 2、獲取url上的參數,/:id的 :
[http://127.0.0.1:8090/user/111](http://127.0.0.1:8090/user/111)
## 路由:**/user/?:id:int**
```
beego.Router("/user/?:id:int", &controllers_user.UserController{})
```
訪問路徑:http://127.0.0.1:8090/user/111
獲取數據:
```
id := c.GetString(":id")
id2 := c.Ctx.Input.Param(":id")
```
?
這種方式不行了:
id3 := c.Input().Get(":id")
## 3、獲取請求信息:
~~~
this.Ctx.Request ? ? ? ? ? ? ? 所有的請求信息
this.Ctx.Request.Header ? ? ? ? 請求頭
this.Ctx.Request.Host ? ? ? ? ? 請求的主機
this.Ctx.Request.Method ? ? ? ? 請求的方法
~~~
## 4、獲取form表單數據:
```
GetString(key string) string
GetStrings(key string) []string
GetInt(key string) (int64, error) ? ? ? ? --返回兩個值
GetBool(key string) (bool, error) ? ? ? ? --返回兩個值
GetFloat(key string) (float64, error) ? ? --返回兩個值
```
??
舉例:前端form表單:
?
```
<form action="/user" method="post">
{{ .xsrfdata }}
? 年齡1:<input type="text" name="age"><br>
? 姓名1:<input type="text" name="name"><br>
? 地址:<input type="text" name="addr"><br>
? 姓名2:<input type="text" name="name"><br>
? 年齡2:<input type="text" name="age"><br>
? 是:<input type="radio" name="is_true" value="true">
? 否:<input type="radio" name="is_true" value="false"><br>
? 價格:<input type="text" name="price"><br>
? <input type="submit" value="提交"><br>
</form>
```
?獲取數據:?
```
name := c.Input().Get("name") 獲取的是第一個name的值
names := c.GetStrings("name") ? 獲取所有的name的值,是個數組
age := c.Input().Get("age")
age,_ := c.GetInt64("age")
is_true , _ := c.GetBool("is_true")
price , _ := c.GetFloat("price")
```
- go環境搭建
- 解決go get網絡慢的問題
- beego的安裝
- bee的安裝
- 編輯器
- go module
- 配置文件詳解
- 配置文件其他說明
- 路由方法
- 路由
- 數據校驗
- 校驗函數
- 頁面跳轉
- 獲取前端數據
- json文件的獲取
- xsrf的用法
- xsrf的防護
- srfs和json的搭配
- flash的用法
- 過濾器
- url反轉
- 各類數據的處理
- 模板函數
- 內置模板函數
- 自定義模板函數
- 模板
- 模板處理
- 模板渲染
- 視圖文件的處理
- 靜態文件
- 請求方式判斷
- 驗證碼
- 另一種方法
- 分頁類
- session
- 登錄判斷
- orm模塊
- 使用方法
- mysql的安裝
- 安裝orm及驅動
- 建立模型
- 自定義模型
- 增刪改查
- 高級查詢
- 常見問題匯總
- 代碼收藏
- 打包部署
- go build打包
- utils收藏
- 新goer容易犯的錯
- 字符串操作