头图
package main

import (
    "encoding/json"
    "fmt"
    "github.com/gin-gonic/gin"
    "net/http"
)

func main()  {
    r := gin.Default()

    r.POST("/json", func(c *gin.Context) {
        data,_ := c.GetRawData()
        var m map[string]interface{}
        _ = json.Unmarshal(data, &m)
        c.JSON(http.StatusOK,m)

    })

    r.LoadHTMLGlob("./temp/*")

    r.GET("/user/add", func(c *gin.Context) {
        c.HTML(http.StatusOK, "useradd.html", gin.H{})
    })

    r.POST("/user/add", func(c *gin.Context) {
        username := c.PostFormArray("username")
        password := c.PostFormArray("password")
        fmt.Println(username, "goubibibi", password)
        c.JSON(http.StatusOK,gin.H{
            "msg":"ok",
            "username":username,
            "password": password,
        })

    })


    r.Run()


}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <form action="/user/add" method="post">
        <p>username: <input type="text" name="username"></p>
        <p>password: <input type="text" name="password"></p>
        <button type="submit"></button>
    </form>


</head>
<body>

</body>
</html>

image.png

image.png

image.png

json 序列化

image.png

结构体

image.png

json反序列化

image.png


锅包肉
97 声望17 粉丝

这个人很懒,没有什么说的。


引用和评论

0 条评论