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,
	})
}

  

posted on 2022-08-24 14:16  fyc春  阅读(81)  评论(0编辑  收藏  举报