gin框架中 1:引入mysql的请求 2:gin.Default()获取,网络请求,get,post,delete方式请求 3:以json map的形式返回 4:以json struct的形式返回 package main import ( "database/sql" "fmt" "github.com/gin-gonic/gin" "log" _"github.com/go-sql-driver/mysql" _"database/sql" ) func main() { conStr := "root:123456@tcp(127.0.0.1:3306)/ginsql" db,err := sql.Open("mysql",conStr) if err != nil { log.Fatal(err.Error()) return } //_, err = db.Exec("create table person(" + // "id int auto_increment primary key," + // "name varchar(12) not null," + // "age int default 1" + // ");") // //if err != nil { // log.Fatal(err.Error()) // return //} _,err = db.Exec("insert into person(name,age)" + "values(?,?);","xiaoming",19) if err != nil { log.Fa
go-gin框架基本网络请求
最新推荐文章于 2023-07-27 11:32:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)