html 原生表单
index.html
<form action="http://127.0.0.1:8081/saveData" method="GET" target="_blank" acccept-charset="UTF-8" ectype="application/x-www-form-urlencoded" autocomplete="on">
<label for="fieldaid">name</label>
<input type="text" id="fieldaid" name="field_a">
<label for="fieldage">age</label>
<input type="text" id="fieldage" name="age">
<input type="submit" value='提交'>
</form>
接口层内容语言go
saveData.go
package GetData
import (
"fmt"
"github.com/gin-gonic/gin"
)
type StructA struct {
Name string `form:"field_a"`
Age int `form:"age"`
}
func SaveData(c *gin.Context) {
var a *StructA = new(StructA)
err := c.ShouldBind(a)
fmt.Println(err)
fmt.Println("field_a=" + c.Query("field_a"))
c.JSON(200, gin.H{
"name": a.Name,
"age": a.Age,
})
}
浙公网安备 33010602011771号