beego框架的最简单登入演示
一.controllers逻辑代码
func (c *UserController) Get() { c.TplName="login.html" } func (c *UserController) Post() { name:=c.GetString("name") password:=c.GetString("password") if name=="maple" && password=="123"{ c.Ctx.WriteString("登入成功") }else { c.Ctx.WriteString("用户名或密码错误") }
二.routers路由代码
func init() { beego.Router("/", &controllers.MainController{}) beego.Router("/user", &controllers.UserController{}) }
三.views模板代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登入</title> </head> <body> <form action="" method="post"> <label for="name">用户名:<input type="text" id="name" name="name"></label> <label for="password">密码:<input type="password" id="password" name="password"></label> <input type="submit" value="登入"> </form> </body> </html>
四.演示图