This is a creation in Article, where the information may have evolved or changed.
Beego Frame
1. Define the route:
Beego. Router ("/updatestate/:statename/:id", &controllers. contentcontroller{}, "*:updatestate")
URL implementations in 2.TPL
The URL in the corresponding TPL file can be considered
<a href= "/updatestate/fbstate/{{.id}}" >{{. Fbstate}}</a>
Where the variables passed to the controller by URL are:
Statename,id, the corresponding value is "Fbstate", and the value obtained through {{. id}}, for example, "3"
3.controller Processing:
Func (c *contentcontroller) Updatestate () {
statename: = c.ctx.input.params[": StateName"]
Idint: = C.ctx.input.param (": id")
ID, _: = StrConv. parseint (idint, 0, 64)
Fmt. PRINTLN (StateName, id)
Success: = models. Updatestate (ID, statename)
If success {
Fmt. Println ("Updatesuccess")
} else {
Fmt. Println ("Updatefail")
}
C.get ()
}
Using the above method, the StateName and ID are obtained, and the methods in the model layer can be called.