Gin学习笔记

Gin学习笔记

Gin文档:https://pkg.go.dev/github.com/gin-gonic/gin

1、快速入门

1.1、安装Gin

go get -u github.com/gin-gonic/gin

1.2、main.go

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {// 创建路由引擎r := gin.Default()// 添加路由监听r.GET("/", func(c *gin.Context) {c.String(http.StatusOK, "Hello Gin!")})//启用 web 服务err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

在这里插入图片描述

2、配置热更新

Air文档:https://github.com/cosmtrek/air

2.1、下载

# 添加air包
go get -u github.com/cosmtrek/air
# 编译并安装air到 $GOPATH/bin 目录(重启一下Goland)
go install github.com/cosmtrek/air@latest

2.2、使用

# 直接使用air即可热加载
air

3、响应数据

3.1、String

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.LoadHTMLGlob("./template/*.html")r.GET("/", func(c *gin.Context) {c.String(http.StatusOK, "Hello Gin!")})r.GET("/hello", func(c *gin.Context) {//c.JSON(http.StatusOK, map[string]interface{}{//	"name": "xumeng03",//	"age":  "24",//})c.JSON(http.StatusOK, gin.H{"name": "xumeng03","age":  "24",})})r.GET("/gin", func(c *gin.Context) {c.HTML(http.StatusOK, "gin.html", gin.H{"path": c.FullPath(),})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

3.2、JSON

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.GET("/hello", func(c *gin.Context) {//c.JSON(http.StatusOK, map[string]interface{}{//	"name": "xumeng03",//	"age":  "24",//})c.JSON(http.StatusOK, gin.H{"name": "xumeng03","age":  "24",})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

3.3、HTML

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.LoadHTMLGlob("./template/*.html")r.GET("/gin", func(c *gin.Context) {c.HTML(http.StatusOK, "gin.html", gin.H{"path": c.FullPath(),})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Gin Study</title>
</head>
<body>
<h1>Gin Study!</h1>
<p>请求路径:{{.path}}</p>
</body>
</html>

4、请求数据

4.1、Get

1、直接查询
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.GET("/", func(c *gin.Context) {// Query 查询 request 的参数,DefaultQuery 同样查询 request 的参数但若未查询到则赋一个默认值//var name = c.Query("name")var name = c.DefaultQuery("name", "Gin")c.String(http.StatusOK, "Hello %s!", name)})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
2、绑定到结构体
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.GET("/", func(c *gin.Context) {var person = Person{}err := c.ShouldBind(&person)if err != nil {c.JSON(http.StatusOK, gin.H{"status":  500,"message": "Params Error!",})return}c.JSON(http.StatusOK, gin.H{"status": 200,"data":   person,})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}type Person struct {Name string `json:"name" form:"name"`Age  string `json:"age" form:"age"`
}

4.2、Post

1、直接查询
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.POST("/", func(c *gin.Context) {// PostForm 查询 request 的参数,DefaultPostForm 同样查询 request 的参数但若未查询到则赋一个默认值var name = c.PostForm("name")var age = c.DefaultPostForm("age", "20")c.String(http.StatusOK, "Hello %s %s!", name, age)})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
2、绑定到结构体(form-data)
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.POST("/", func(c *gin.Context) {var person = Person{}err := c.ShouldBind(&person)if err != nil {c.JSON(http.StatusOK, gin.H{"status":  500,})return}c.JSON(http.StatusOK, gin.H{"status":  500,"data": person,})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}type Person struct {Name string `json:"name" form:"name"`Age  string `json:"age" form:"age"`
}
3、绑定到结构体(json)
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.POST("/json", func(c *gin.Context) {var person = Person{}err := c.ShouldBindJSON(&person)if err != nil {c.JSON(http.StatusOK, gin.H{"status": 500,})return}c.JSON(http.StatusOK, gin.H{"status": 200,"data":   person,})})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}type Person struct {Name string `json:"name" form:"name"`Age  string `json:"age" form:"age"`
}

5、Restful

http://127.0.0.1/item/1 查询,GET

http://127.0.0.1/item 新增,POST

http://127.0.0.1/item 更新,PUT

http://127.0.0.1/item/1 删除,DELETE

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()r.GET("/get/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello get %s!", param)})r.POST("/post/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello post %s!", param)})r.PUT("/put/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello put %s!", param)})r.DELETE("/delete/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello delete %s!", param)})err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

6、路由分组

6.1、基本使用

package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()group := r.Group("/restful0"){group.GET("/get/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello get %s!", param)})group.POST("/post/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello post %s!", param)})}group1 := r.Group("/restful1"){group1.PUT("/put/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello put %s!", param)})group1.DELETE("/delete/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello delete %s!", param)})}err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

6.2、拆分文件

package mainimport ("ginstudy/router""github.com/gin-gonic/gin"
)func main() {r := gin.Default()router.Restful0(r)router.Restful1(r)err := r.Run()if err != nil {return} // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
package routerimport ("github.com/gin-gonic/gin""net/http"
)func Restful0(r *gin.Engine) {group := r.Group("/restful0"){group.GET("/get/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello get %s!", param)})group.POST("/post/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello post %s!", param)})}
}
package routerimport ("github.com/gin-gonic/gin""net/http"
)func Restful1(r *gin.Engine) {group1 := r.Group("/restful1"){group1.PUT("/put/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello put %s!", param)})group1.DELETE("/delete/:name", func(c *gin.Context) {param := c.Param("name")c.String(http.StatusOK, "Hello delete %s!", param)})}
}

7、自定义控制器

7.1、目录结构

在这里插入图片描述

7.2、router

app.go

package appimport ("ginstudy/controller/app""github.com/gin-gonic/gin"
)func AppApi(r *gin.Engine) {group := r.Group("/app/api")appController := app.AppController{}group.GET("/", appController.Index)
}

web.go

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Index)
}

7.3、controller

app.go

package appimport ("ginstudy/controller""github.com/gin-gonic/gin"
)type AppController struct {controller.StandardController
}func (app AppController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello App Api!")app.Success(c)
}

web.go

package webimport ("ginstudy/controller""github.com/gin-gonic/gin"
)type WebController struct {controller.StandardController
}func (web WebController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello Web Api!")web.Success(c)
}

standard.go

package controllerimport ("github.com/gin-gonic/gin""net/http"
)type StandardController struct{}func (standard StandardController) Success(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 200,})
}func (standard StandardController) Error(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 500,})
}

7.4、main

package mainimport ("ginstudy/router/app""ginstudy/router/web""github.com/gin-gonic/gin"
)func main() {r := gin.Default()app.AppApi(r)web.WebApi(r)err := r.Run()if err != nil {return}
}

7.5、go.mod

module ginstudygo 1.20require (dario.cat/mergo v1.0.0 // indirectgithub.com/bep/godartsass v1.2.0 // indirectgithub.com/bep/godartsass/v2 v2.0.0 // indirectgithub.com/bep/golibsass v1.1.1 // indirectgithub.com/bytedance/sonic v1.10.2 // indirectgithub.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirectgithub.com/chenzhuoyu/iasm v0.9.1 // indirectgithub.com/cli/safeexec v1.0.1 // indirectgithub.com/cosmtrek/air v1.49.0 // indirectgithub.com/creack/pty v1.1.20 // indirectgithub.com/fatih/color v1.15.0 // indirectgithub.com/fsnotify/fsnotify v1.7.0 // indirectgithub.com/gabriel-vasile/mimetype v1.4.3 // indirectgithub.com/gin-contrib/sse v0.1.0 // indirectgithub.com/gin-gonic/gin v1.9.1 // indirectgithub.com/go-playground/locales v0.14.1 // indirectgithub.com/go-playground/universal-translator v0.18.1 // indirectgithub.com/go-playground/validator/v10 v10.16.0 // indirectgithub.com/goccy/go-json v0.10.2 // indirectgithub.com/gohugoio/hugo v0.120.3 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/cpuid/v2 v2.2.5 // indirectgithub.com/leodido/go-urn v1.2.4 // indirectgithub.com/mattn/go-colorable v0.1.13 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirectgithub.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirectgithub.com/modern-go/reflect2 v1.0.2 // indirectgithub.com/pelletier/go-toml v1.9.5 // indirectgithub.com/pelletier/go-toml/v2 v2.1.0 // indirectgithub.com/spf13/afero v1.10.0 // indirectgithub.com/tdewolff/parse/v2 v2.7.4 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirectgithub.com/ugorji/go/codec v1.2.11 // indirectgolang.org/x/arch v0.6.0 // indirectgolang.org/x/crypto v0.14.0 // indirectgolang.org/x/net v0.17.0 // indirectgolang.org/x/sys v0.14.0 // indirectgolang.org/x/text v0.14.0 // indirectgoogle.golang.org/protobuf v1.31.0 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect
)

8、中间处理程序

8.1、基本使用

standard.go

package controllerimport ("fmt""github.com/gin-gonic/gin""net/http"
)type StandardController struct{}func (standard StandardController) Success(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 200,})
}func (standard StandardController) Error(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 500,})
}func (standard StandardController) Aop(c *gin.Context) {fmt.Println("aop start")// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop end")
}

web.go

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Aop, webController.Index)
}

app.go

package appimport ("ginstudy/controller/app""github.com/gin-gonic/gin"
)func AppApi(r *gin.Engine) {group := r.Group("/app/api")appController := app.AppController{}group.GET("/", appController.Aop, appController.Index)
}

8.2、多中间处理程序

standard.go

package controllerimport ("fmt""github.com/gin-gonic/gin""net/http"
)type StandardController struct{}func (standard StandardController) Success(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 200,})
}func (standard StandardController) Error(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 500,})
}func (standard StandardController) Aop1(c *gin.Context) {fmt.Println("aop1 start")// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop1 end")
}func (standard StandardController) Aop2(c *gin.Context) {fmt.Println("aop2 start")// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop2 end")
}

web.go

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Aop1, webController.Aop2, webController.Index)
}

app.go

package appimport ("ginstudy/controller/app""github.com/gin-gonic/gin"
)func AppApi(r *gin.Engine) {group := r.Group("/app/api")appController := app.AppController{}group.GET("/", appController.Aop1, appController.Aop2, appController.Index)
}

8.3、全局中间处理程序

路由组也可单独配置中间处理程序!

main.go

package mainimport ("ginstudy/controller""ginstudy/router/app""ginstudy/router/web""github.com/gin-gonic/gin"
)func main() {standardController := controller.StandardController{}r := gin.Default()r.Use(standardController.Aop1, standardController.Aop2)app.AppApi(r)web.WebApi(r)err := r.Run()if err != nil {return}
}

web.go

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Index)
}

app.go

package appimport ("ginstudy/controller/app""github.com/gin-gonic/gin"
)func AppApi(r *gin.Engine) {group := r.Group("/app/api")appController := app.AppController{}group.GET("/", appController.Index)
}

8.4、中间处理程序通信

standard.go

package controllerimport ("fmt""github.com/gin-gonic/gin""net/http"
)type StandardController struct{}func (standard StandardController) Success(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 200,})
}func (standard StandardController) Error(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 500,})
}func (standard StandardController) Aop1(c *gin.Context) {fmt.Println("aop1 start")c.Set("name", "xumeng03")// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop1 end")
}func (standard StandardController) Aop2(c *gin.Context) {fmt.Println("aop2 start")fmt.Println(c.Get("name"))// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop2 end")
}

8.5、协程中使用中间处理程序

standard.go

package controllerimport ("fmt""github.com/gin-gonic/gin""net/http""time"
)type StandardController struct{}func (standard StandardController) Success(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 200,})
}func (standard StandardController) Error(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": 500,})
}func (standard StandardController) Aop1(c *gin.Context) {fmt.Println("aop1 start")c.Set("name", "xumeng03")// 放行请求c.Next()// 拒绝请求//c.Abort()fmt.Println("aop1 end")
}func (standard StandardController) Aop2(c *gin.Context) {fmt.Println("aop2 start")fmt.Println(c.Get("name"))// 放行请求c.Next()// 拒绝请求//c.Abort()// 不能直接使用gin.Context,需要使用c.Copy()获取gin.Context的副本// c.Copy()只会复制gin.Context结构体中的字段值,并不会复制底层的请求和响应对象cc := c.Copy()go func() {time.Sleep(5 * time.Second)fmt.Println(cc.Request.URL.Path, "被访问了")}()fmt.Println("aop2 end")
}

9、自定义模块

package utilsimport "time"func UnixToDatetime(unix int64) string {return time.Unix(unix, 0).Format("2006-01-02 15:04:05")
}

10、文件上传

10.1、单文件上传

在这里插入图片描述

router/webgo

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Index)group.POST("/upload", webController.Upload)
}

controller/web.go

package webimport ("fmt""ginstudy/controller""github.com/gin-gonic/gin""path"
)type WebController struct {controller.StandardController
}func (web WebController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello Web Api!")fmt.Println("Hello Web Api!")web.Success(c)
}func (web WebController) Upload(c *gin.Context) {file, err := c.FormFile("file")if err != nil {fmt.Println("upload error!")}fmt.Println(file.Filename)// 路径为main.go所在目录p := path.Join("static", file.Filename)err = c.SaveUploadedFile(file, p)if err != nil {fmt.Println(err)return}web.Success(c)
}

10.2、多文件上传

在这里插入图片描述

router/webgo

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Index)group.POST("/uploads", webController.Uploads)
}

controller/web.go

package webimport ("fmt""ginstudy/controller""github.com/gin-gonic/gin""path"
)type WebController struct {controller.StandardController
}func (web WebController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello Web Api!")fmt.Println("Hello Web Api!")web.Success(c)
}func (web WebController) Uploads(c *gin.Context) {form, _ := c.MultipartForm()fmt.Println(form)files := form.File["files"]for k, file := range files {fmt.Println(k, file.Filename)p := path.Join("static", file.Filename)err := c.SaveUploadedFile(file, p)if err != nil {return}}web.Success(c)
}

11、Cookie&Session

11.1、cookie

package webimport ("fmt""ginstudy/controller""github.com/gin-gonic/gin""path"
)type WebController struct {controller.StandardController
}func (web WebController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello Web Api!")fmt.Println("Hello Web Api!")web.Success(c)
}func (web WebController) Cookie(c *gin.Context) {// name: cookie 名称// value: cookie 值// maxAge: 存活时间,单位秒(等于0则一直存活,小于0则删除cookie)// path: cookie 可用路径// domain: cookie 可用域名,如需在多个二级域名下共享,设置时需设置为“.bilibili.com”格式// secure: 是否只在 https 启用// httponly: cookie仅后端可操作cookie, err := c.Cookie("GinStudy")if err != nil {fmt.Println(err)}if cookie == "" {c.SetCookie("GinStudy", "xumeng03", 3600, "/", "localhost", false, false)}web.Success(c)
}

11.2、session

https://github.com/gin-contrib/sessions#redis

1、安装
go get github.com/gin-contrib/sessions
2、设置存储引擎

main.go

package mainimport ("ginstudy/router/app""ginstudy/router/web""github.com/gin-contrib/sessions""github.com/gin-contrib/sessions/cookie""github.com/gin-gonic/gin"
)func main() {r := gin.Default()// 创建基于cookie的存储引擎store := cookie.NewStore([]byte("Ginstudy"))r.Use(sessions.Sessions("session", store))app.AppApi(r)web.WebApi(r)err := r.Run()if err != nil {return}
}
3、使用session

router/web.go

package webimport ("ginstudy/controller/web""github.com/gin-gonic/gin"
)func WebApi(r *gin.Engine) {group := r.Group("/web/api")webController := web.WebController{}group.GET("/", webController.Index)group.GET("/session", webController.Session)
}

controller/web.go

package webimport ("fmt""ginstudy/controller""github.com/gin-contrib/sessions""github.com/gin-gonic/gin""path"
)type WebController struct {controller.StandardController
}func (web WebController) Index(c *gin.Context) {//c.String(http.StatusOK, "Hello Web Api!")fmt.Println("Hello Web Api!")web.Success(c)
}func (web WebController) Session(c *gin.Context) {// 获取sessionsession := sessions.Default(c)name := session.Get("name")if name == nil {session.Set("name", "xumeng03")// 设置值(需要手动保存)session.Save()} else {fmt.Println(name)}web.Success(c)
}

11.3、分布式session

待补。。。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/134502.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode 热题100——链表专题(二)

一、环形链表 141.环形链表&#xff08;题目链接&#xff09; 思路&#xff1a;使用快慢指针&#xff0c;慢指针走一步&#xff0c;快指针走俩步&#xff0c;如果是环形链表&#xff0c;那么快慢指针一定相遇&#xff0c;如果不是环形结构那么快指针或者快指针的next一定先为N…

概率论和数理统计(一)概率的基本概念

前言 生活中对于事件的发生,可以概括为 确定现象&#xff1a;在一定条件下必然发生&#xff0c;如日出随机现象&#xff1a;在个别试验中其结果呈现出不确定性&#xff0c;在大量重复试验中其结果又具有统计规律的现象&#xff0c;称之为随机现象。 随机现象的特点&#xff…

TCP/IP的基础知识

文章目录 TCP/IP的基础知识硬件&#xff08;物理层&#xff09;网络接口层&#xff08;数据链路层&#xff09;互联网层&#xff08;网络层&#xff09;TCP/IP的具体含义传输层应用层&#xff08;会话层以上的分层&#xff09;TCP/IP分层模型与通信示例发送数据包的一个例子接收…

【公益案例展】火山引擎公益电子票据服务——连接善意,共创美好

‍ 火山引擎公益案例 本项目案例由火山引擎投递并参与数据猿与上海大数据联盟联合推出的 #榜样的力量# 《2023中国数据智能产业最具社会责任感企业》榜单/奖项”评选。 大数据产业创新服务媒体 ——聚焦数据 改变商业 捐赠票据是慈善组织接受捐赠后给捐赠方开具的重要凭证&…

Mybatis与Mybatis-Plus(注解与Xml)(单表与多表)

准备工作 这里我们准备了两个与数据库表对应的实体类&#xff0c;stu为学生表&#xff0c;cls为班级表 类属性上的注解如 TableId等 为Mybatis-Plus的注解&#xff0c;使用mybatis会无视掉这些注解 在Stu 类的最后一个属性我们定义了Cls实体类的对象&#xff0c;对于单表查询&…

Dcoker学习笔记(一)

Dcoker学习笔记一 一、 初识Docker1.1 简介1.2 虚拟机和docker的区别1.3 Docker架构1.4 安装Docker&#xff08;Linux&#xff09; 二、 Dcoker基本操作2.1 镜像操作2.2 容器操作练习 2.3 数据卷volume&#xff08;容器数据管理&#xff09;简介数据卷语法数据卷挂载 2.4 自定义…

高性能三防工业平板电脑 防摔防爆电容屏工控平板

HT1000是一款高性能工业三防平板&#xff0c;10.1英寸超清大屏&#xff0c;厚度仅14.9mm&#xff0c;超薄机身&#xff0c;可轻松插入袋中&#xff0c;方便携带&#xff0c;搭载8核2.0GHz高性能CPU&#xff0c;行业领先的Android 11.0&#xff0c;设备性能大幅提升&#xff0c;…

机器人制作开源方案 | 管内检测维护机器人

一、作品简介 作者&#xff1a;李泽彬&#xff0c;李晋晟&#xff0c;杜张坤&#xff0c;禹馨雅 单位&#xff1a;运城学院 指导老师&#xff1a;薛晓峰 随着我国的社会主义市场经济的飞速发展和科学技术的革新&#xff0c;各行各业的发展越来越离不开信息化和网络化的…

【深度学习】卷积层填充和步幅以及其大小关系

参考链接 【深度学习】&#xff1a;《PyTorch入门到项目实战》卷积神经网络2-2&#xff1a;填充(padding)和步幅(stride) 一、卷积 卷积是在深度学习中的一种重要操作&#xff0c;但实际上它是一种互相关操作&#xff0c;&#xff0c;首先我们来了解一下二维互相关&#xff…

ros1 自定义topic 主题的发布,监听以及和消息体的定义

1. 在功能包下新增msg 文件夹 在功能包的下面新建 msg 文件夹&#xff0c;如下图所示 2. 新增Person.msg 消息实体 右键打开命令框&#xff0c;输入 touch Person.msg 就会在msg 目录下新增 Person.msg 文件 在Person.msg中输入如下内容完成.msg文件的创建&#xff0c;msg文…

关于卷积神经网络中如何计算卷积核大小(kernels)

首先需要说明的一点是&#xff0c;虽然卷积层得名于卷积&#xff08; convolution &#xff09;运算&#xff0c;但我们通常在卷积层中使用更加直观的计算方式&#xff0c;叫做互相关&#xff08; cross-correlation &#xff09;运算。 也就是说&#xff0c;其实我们现在在这里…

安装 Node.js

首先&#xff0c;我们需要安装 Node.js 和相关的库&#xff0c;如 request 和 cheerio。 npm install request cheerio然后&#xff0c;我们可以使用以下代码来爬取网页内容&#xff1a; const request require(request); const cheerio require(cheerio);request({url: js…

基于ubuntu1604的ROS安装

不同版本的Ubuntu都有对应的ROS版本&#xff0c;不要强行安装不对应的版本&#xff0c;否则遇到问题会很难找到解决方法。此教程也只是基于Ubuntu1604和kinetic版本的ROS。 一、基本流程 以下命令仅记录执行顺序&#xff0c;不要无脑复制执行&#xff0c;重在理解 #基本更新…

Linux学习第35天:Linux LCD 驱动实验(二):星星之火可以燎原

Linux版本号4.1.15 芯片I.MX6ULL 大叔学Linux 品人间百味 思文短情长 三、LCD驱动程序编写 需要注意的地方&#xff1a; ①、 LCD 所使用的 IO 配置。 ②、 LCD 屏幕节点修改&#xff0c;修改相应的属性值&#xff0c;换成我们所使…

JavaScript爬虫程序爬取游戏平台数据

这次我用一个JavaScript爬虫程序&#xff0c;来爬取游戏平台采集数据和分析的内容。爬虫使用了爬虫IP信息&#xff0c;爬虫IP主机为duoip&#xff0c;爬虫IP端口为8000。以下是每行代码和步骤的解释&#xff1a; // 导入所需的库 const axios require(axios); const cheerio …

京东数据分析:2023年9月京东打印机行业品牌销售排行榜

鲸参谋监测的京东平台9月份打印机市场销售数据已出炉&#xff01; 鲸参谋数据显示&#xff0c;今年9月&#xff0c;京东平台打印机的销量为60万&#xff0c;环比增长约32%&#xff0c;同比下滑约25%&#xff1b;销售额为5亿&#xff0c;环比增长约35%&#xff0c;同比下滑约29%…

Notepad++中删除连续的任意n行

使用Notepad里的行标记功能&#xff0c;可以删除指定的任意n行。 案例1&#xff0c;删除sample2.dat里的第201行到第10000行。方法如下&#xff1a; (1) 用户NotePad打开sample2.dat&#xff0c;右击201行 —》“开始/结束”/开始 图(1) 选择行的起点&#xff1a;201 (2) 接…

做什么数据表格啊,要做就做数据可视化

是一堆数字更易懂&#xff0c;还是图表更易懂&#xff1f;很明显是图表&#xff0c;特别是数据可视化图表。数据可视化是一种将大量数据转化为视觉形式的过程&#xff0c;通过图形、图表、图像等方式呈现数据&#xff0c;以便更直观地理解和分析。 数据可视化更加生动、形象地…

蓝桥杯每日一题203.11.7

题目描述 题目分析 使用dp思维&#xff0c;当前位置是否可行是有上一位置推来&#xff0c;计算出最大的可行位置即可 #include <stdio.h> #include <string.h>#define N 256 int f(const char* s1, const char* s2) {int a[N][N];int len1 strlen(s1);int len2 …

kafka笔记要点和集群安装、消息分组、消费者分组以及与storm的整合机制

kafka笔记 1/kafka是一个分布式的消息缓存系统 2/kafka集群中的服务器都叫做broker 3/kafka有两类客户端&#xff0c;一类叫producer&#xff08;消息生产者&#xff09;&#xff0c;一类叫做consumer&#xff08;消息消费者&#xff09;&#xff0c;客户端和broker服务器之间…