Beego获取请求参数
页面表单:
<form action='/get' method='Post'> <tr> <th>用户名</th> <td> <input type='text' name='username'> </td> </tr> <tr> <th>密码</th> <td> <input type='text' name='password'> </td> <tr> <th colspan='2'> <button id='login'>Login</button> </th> </tr> </tr> </form
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
自定义controllers:
//自定义控制器02
type ObjectController struct {
beego.Controller
}
//实现Post方法
func (this *ObjectController) Post() {
username := this.GetString('username')
password := this.GetString('password')
fmt.Println(username, password)
this.TplName = 'main.tpl'
}
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
URL参数也是一样获取,Beego框架智能的为我们解析了请求参数,我们只需要通过key来获取即可
赞 (0)