gin框架精通篇(二)

news2024/10/5 0:27:38

原生数据库使用

导入模块:go get -u github.com/go-sql-driver/mysql

安装 mysql 数据库

安装数据库可能遇到的问题:(网上的方法基本可以解决)
ERROR 1045 (28000): Access denied for user ‘-root’@‘localhost’ (using password: YES)
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

可视化数据库操作

在这里插入图片描述

// 导包内容
package main

import (
    "database/sql" // 导入sql包处理数据库操作
    "fmt" // 导入fmt包进行格式化输出和错误输出
    "github.com/gin-gonic/gin" // 导入gin包快速构建REST API
    _ "github.com/go-sql-driver/mysql" // 导入MySQL驱动
    "net/http" // 导入http包处理HTTP请求
)

注意别漏了:_ “github.com/go-sql-driver/mysql” // 导入MySQL驱动

var sqlDb *sql.DB // 声明一个sql.DB指针,用于后续的数据库操作
var sqlResponse SqlResponse // sqlResponse是全局的用于封装http返回的结构体
/** 请求结构体 和 响应结构体 */
// SqlUser结构体映射数据库中的user表
type SqlUser struct {
    Name    string `json:"name"` // 用户名
    Age     int    `json:"age"` // 年龄
    Address string `json:"address"` // 地址
}
// SqlResponse结构体用于封装http响应数据
type SqlResponse struct {
    Code    int         `json:"code"` // 响应状态码
    Message string      `json:"message"` // 响应消息
    Data    interface{} `json:"data"` // 响应数据
}
// init函数用于初始化数据库
func init() {
    // MySQL连接字符串
    sqlStr := "root:123456@tcp(127.0.0.1:3306)/testdb?charset=utf8&parseTime=true&loc=Local"
    var err error
    // 打开MySQL连接
    sqlDb, err = sql.Open("mysql", sqlStr)
    if err != nil {
        // 如果连接出错,则输出错误并返回
        fmt.Println("数据库打开出现了问题:", err)
        return
    }
    // 测试与数据库的连接是否存活
    err = sqlDb.Ping()
    if err != nil {
        fmt.Println("数据库打开出现了问题:", err)
        return
    }
}
// 主函数
func main() {
	r := gin.Default()

	r.POST("/sql/insert", insertData)
	r.GET("/sql/read", readData)
	r.GET("/sql/readAll", readAllData)
	r.PUT("/sql/update", updateData)
	r.DELETE("/sql/del", delData)

	r.Run(":9090")
}

// insertData函数处理插入数据的请求
func insertData(context *gin.Context) {
    var u SqlUser
    // 绑定请求中的JSON数据到u结构体
    err := context.Bind(&u)
    if err != nil {
        // 如果绑定出错,设置响应结构体并返回JSON响应
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "参数错误"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }
    // 定义插入SQL语句
    sqlStr := "insert into user(name, age, address) values (?,?,?)"
    // 执行插入操作
    ret, err := sqlDb.Exec(sqlStr, u.Name, u.Age, u.Address)
    if err != nil {
        // 如果插入出错,设置响应结构体并返回JSON响应
        fmt.Println(err)
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "写入失败"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }
    // 插入成功,设置响应结构体
    sqlResponse.Code = http.StatusOK
    sqlResponse.Message = "写入成功"
    sqlResponse.Data = "OK"
    // 返回JSON响应
    context.JSON(http.StatusOK, sqlResponse)
    // 打印插入的ID
    fmt.Println(ret.LastInsertId())
}

在这里插入图片描述

// readData函数处理读取数据的请求:单条数据
func readData(context *gin.Context) {
    name := context.Query("name") // 从查询参数获取name
    // 定义查询SQL语句
    sqlStr := "select age,address from user where name=?"
    var u SqlUser
    // 执行查询,并扫描结果到u结构体
    err := sqlDb.QueryRow(sqlStr, name).Scan(&u.Age, &u.Address)
    if err != nil {
        // 如果查询出错,设置响应结构体并返回JSON响应
        fmt.Println(err)
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "读取失败"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }
    // 查询成功,填充姓名,并设置响应结构体
    u.Name = name
    sqlResponse.Code = http.StatusOK
    sqlResponse.Message = "读取成功"
    sqlResponse.Data = u
    // 返回JSON响应
    context.JSON(http.StatusOK, sqlResponse)
}

在这里插入图片描述

func readAllData(context *gin.Context) {
    // 从Http请求中获取地址参数(address)
    address := context.Query("address")

    // 定义SQL查询语句,根据特定地址(address)查询与之匹配的所有用户名称(name)和用户年龄(age)
    sqlStr := "select name, age from user where address=?"

    // 使用预定义的sqlDb对象执行刚刚定义的SQL查询语句
    rows, err := sqlDb.Query(sqlStr, address)

    // 如果在执行SQL查询语句过程中出现错误,将错误信息打印到控制台,并向HTTP响应中写入相应的错误信息,然后退出当前函数
    if err != nil {
        fmt.Println(err)
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "读取失败"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 定时关闭数据库连接
    defer rows.Close()

    // 定义一个空切片,用来存储所有查询到的用户数据
    resUser := make([]SqlUser, 0)

    // 遍历数据库查询结果集rows,提取所有的数据并添加到之前定义的用于存储用户数据的切片中
    for rows.Next() {
        var userTemp SqlUser
        // 将从结果集中获取到的每一行数据相应的字段(name, age)提取出来,赋值给用户结构体(userTemp)对应的字段
        rows.Scan(&userTemp.Name, &userTemp.Age)
        // 将地址字段值设置为查询参数
        userTemp.Address = address
        // 将该用户结构体添加到用户切片中
        resUser = append(resUser, userTemp)
    }

    // 设置HTTP响应的状态码、消息和数据内容,然后将其写入到HTTP响应中。这里写入的数据内容就是查询到的所有用户数据
    sqlResponse.Code = http.StatusOK
    sqlResponse.Message = "读取成功"
    sqlResponse.Data = resUser
    context.JSON(http.StatusOK, sqlResponse)
}

在这里插入图片描述

func updateData(context *gin.Context) {
    // 定义一个SqlUser类型的变量u,用于存储请求中的用户数据
    var u SqlUser
    // 定义一个整型变量count,用于存储数据库查询返回的计数结果
    var count int

    // 使用context.Bind()方法从HTTP请求体中提取数据并绑定到变量u中
    err := context.Bind(&u)
    // 如果在数据绑定过程中发生错误,则向客户端发送参数错误的响应
    if err != nil {
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "参数错误"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 定义SQL查询字符串,用于检查具有特定名称的用户是否存在于数据库中
    sqlStr := "select count(*) from user where name=?"
    // 执行SQL查询,将查询结果(即用户的数量)存储于变量count中
    err = sqlDb.QueryRow(sqlStr, u.Name).Scan(&count)
    // 如果查询结果显示用户数量为0或查询时发生错误,则向客户端发送数据不存在的响应
    if count <= 0 || err != nil {
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "更新的数据不存在"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 定义SQL更新字符串,用于更新用户的年龄(age)和地址(address)
    upStr := "update user set age=?, address=? where name=?"
    // 执行SQL更新操作
    ret, err := sqlDb.Exec(upStr, u.Age, u.Address, u.Name)
    // 如果在执行更新操作时发生错误,则向客户端发送更新失败的响应
    if err != nil {
        fmt.Println(err)
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "更新失败"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 如果更新操作成功,向客户端发送更新成功的响应
    sqlResponse.Code = http.StatusOK
    sqlResponse.Message = "更新成功"
    sqlResponse.Data = "OK"
    context.JSON(http.StatusOK, sqlResponse)

    // 打印到控制台SQL操作返回的结果,这通常用于调试
    // 注意:这里的LastInsertId()在更新操作中可能不会返回有意义的值,需要注意其适用场景
    fmt.Println(ret.LastInsertId())
}

在这里插入图片描述

func delData(context *gin.Context) {
    // 从HTTP请求的查询参数中获取需要删除的用户的名称
    name := context.Query("name")
    // 定义一个整型变量count,用于存储数据库查询返回的计数结果
    var count int

    // 定义SQL查询字符串,用于检查具有特定名称的用户是否存在于数据库中
    sqlStr := "select count(*) from user where name=?"
    // 执行SQL查询,将查询结果(即用户的数量)存储于变量count中
    err := sqlDb.QueryRow(sqlStr, name).Scan(&count)
    // 如果查询结果显示用户数量为0或查询时发生错误,则向客户端发送数据不存在的响应
    if count <= 0 || err != nil {
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "删除的数据不存在"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 定义SQL删除字符串,用于从数据库中删除具有特定名称的用户
    delStr := "delete from user where name=?"
    // 执行SQL删除操作
    ret, err := sqlDb.Exec(delStr, name)
    // 如果在执行删除操作时发生错误,则向客户端发送删除失败的响应
    if err != nil {
        sqlResponse.Code = http.StatusBadRequest
        sqlResponse.Message = "删除的数据不存在"
        sqlResponse.Data = "error"
        context.JSON(http.StatusOK, sqlResponse)
        return
    }

    // 如果删除成功,向客户端发送删除成功的响应
    sqlResponse.Code = http.StatusOK
    sqlResponse.Message = "删除成功"
    sqlResponse.Data = "OK"
    context.JSON(http.StatusOK, sqlResponse)

    // 打印到控制台SQL操作返回的结果,这通常用于调试
    // 注意:这里的LastInsertId()在删除操作中可能不会返回有意义的值,因为它更适用于插入操作
    fmt.Println(ret.LastInsertId())
}

在这里插入图片描述

xorm框架

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql" // 导入MySQL驱动
	"github.com/go-xorm/xorm"
	"net/http"
	"time"
)

var x *xorm.Engine
var xormResponse XormResponse

type Stu struct {
	Id      int64     `xorm:"pk autoincr" json:"id"`
	StuNum  string    `xorm:"unique" json:"stu_num"`
	Name    string    `json:"name"`
	Age     int       `json:"age"`
	Created time.Time `xorm:"created" json:"created"`
	Updated time.Time `xorm:"updated" json:"updated"`
}

type XormResponse struct {
	Code    int         `json:"code"`    // 响应状态码
	Message string      `json:"message"` // 响应消息
	Data    interface{} `json:"data"`    // 响应数据
}
func init() {
	sqlStr := "root:123456@tcp(127.0.0.1:3306)/xorm?charset=utf8&parseTime=true&loc=Local"
	var err error
	x, err = xorm.NewEngine("mysql", sqlStr)
	if err != nil {
		fmt.Println("数据库连接失败", err)
		return
	}
	err = x.Sync(new(Stu))
	if err != nil {
		fmt.Println("数据库同步错误", err)
		return
	}
	fmt.Println("数据库初始化成功", err)
}
func main() {
	r := gin.Default()

	r.POST("/xorm/insert", insertData)
	r.GET("/xorm/read", readData)
	r.GET("/xorm/mulread", mulReadData)
	r.PUT("/xorm/update", xormUpdateData)
	r.DELETE("/xorm/del", delData)

	r.Run(":9090")
}
func insertData(context *gin.Context) {
	var s Stu
	err := context.Bind(&s)
	if err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "参数错误"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	affected, err := x.Insert(s)
	if affected <= 0 || err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "写入失败"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	xormResponse.Code = http.StatusOK
	xormResponse.Message = "写入成功"
	xormResponse.Data = "OK"
	context.JSON(http.StatusOK, xormResponse)
}

在这里插入图片描述

func readData(context *gin.Context) {
	stuNum := context.Query("stu_num")
	var stus []Stu
	err := x.Where("stu_num=?", stuNum).Find(&stus)
	if err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "查询错误"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	xormResponse.Code = http.StatusOK
	xormResponse.Message = "查询成功"
	xormResponse.Data = stus
	context.JSON(http.StatusOK, xormResponse)
}

在这里插入图片描述

func mulReadData(context *gin.Context) {
	name := context.Query("name")
	var stus []Stu
	err := x.Where("name=?", name).And("age>20").Limit(10, 0).Asc("age").Find(&stus)
	if err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "查询错误"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	xormResponse.Code = http.StatusOK
	xormResponse.Message = "查询成功"
	xormResponse.Data = stus
	context.JSON(http.StatusOK, xormResponse)
}

在这里插入图片描述

func xormUpdateData(context *gin.Context) {
	var s Stu
	err := context.Bind(&s)
	if err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "参数错误"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	var stus []Stu
	err = x.Where("stu_num=?", s.StuNum).Find(&stus)
	if err != nil || len(stus) <= 0 {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "数据不存在"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	affected, err := x.Where("stu_num=?", s.StuNum).Update(&Stu{Name: s.Name, Age: s.Age})
	if err != nil || affected <= 0 {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "修改失败"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	xormResponse.Code = http.StatusBadRequest
	xormResponse.Message = "修改成功"
	xormResponse.Data = "OK"
	context.JSON(http.StatusOK, xormResponse)
}

在这里插入图片描述

func delData(context *gin.Context) {
	stuNum := context.Query("stu_num")
	var stus []Stu
	err := x.Where("name=?", stuNum).Find(&stus)
	if err != nil {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "没有此条数据"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	affected, err := x.Where("stu_num=?", stuNum).Delete(&Stu{})
	if err != nil || affected <= 0 {
		xormResponse.Code = http.StatusBadRequest
		xormResponse.Message = "删除失败"
		xormResponse.Data = "error"
		context.JSON(http.StatusOK, xormResponse)
		return
	}
	xormResponse.Code = http.StatusBadRequest
	xormResponse.Message = "删除成功"
	xormResponse.Data = "OK"
	context.JSON(http.StatusOK, xormResponse)
}

在这里插入图片描述

gorm框架

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"net/http"
	"time"
)

type Product struct {
	ID             int       `gorm:"primaryKey;autoIncrement" json:"id"`
	Number         string    `gorm:"unique" json:"number"`
	Category       string    `gorm:"type:varchar(256);not null" json:"category"`
	Name           string    `gorm:"type:varchar(20);not null" json:"name"`
	MadeIn         string    `gorm:"type:varchar(128);not null" json:"madeIn"`
	ProductionTime time.Time `json:"production_time"`
}

type GormResponse struct {
	Code    int         `json:"code"`    // 响应状态码
	Message string      `json:"message"` // 响应消息
	Data    interface{} `json:"data"`    // 响应数据
}

var gormResponse GormResponse

var gormDB *gorm.DB
func init() {
	var err error
	sqlStr := "root:123456@tcp(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=true&loc=Local"
	gormDB, err = gorm.Open(mysql.Open(sqlStr), &gorm.Config{})
	if err != nil {
		fmt.Println("数据库连接失败", err)
		return
	}
}

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

	r.POST("/gorm/insert", insetData)
	r.GET("/gorm/read", readData)
	r.GET("/gorm/readAll", readAllData)
	r.PUT("/gorm/update", updateData)
	r.DELETE("/gorm/del", delData)

	r.Run(":9090")
}
func errorTouch(context *gin.Context) {
	defer func() {
		err := recover()
		if err != nil {
			gormResponse.Code = http.StatusBadRequest
			gormResponse.Message = "错误"
			gormResponse.Data = err
			context.JSON(http.StatusOK, gormResponse)
		}
	}()
}
func insetData(context *gin.Context) {
	errorTouch(context)
	var p Product
	err := context.Bind(&p)
	if err != nil {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "参数错误"
		gormResponse.Data = err
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	tx := gormDB.Create(&p)
	if tx.RowsAffected <= 0 {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "写入失败"
		gormResponse.Data = "error"
		context.JSON(http.StatusBadRequest, gormResponse)
		return
	}
	gormResponse.Code = http.StatusOK
	gormResponse.Message = "写入成功"
	gormResponse.Data = "ok"
	context.JSON(http.StatusOK, gormResponse)
}

在这里插入图片描述

func readData(context *gin.Context) {
	errorTouch(context)
	number := context.Query("number")
	product := Product{}
	tx := gormDB.Where("number=?", number).First(&product)
	if tx.Error != nil {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "查询错误"
		gormResponse.Data = tx.Error
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	gormResponse.Code = http.StatusBadRequest
	gormResponse.Message = "查询成功"
	gormResponse.Data = product
	context.JSON(http.StatusOK, gormResponse)
}

在这里插入图片描述

func readAllData(context *gin.Context) {
	category := context.Query("category")
	products := make([]Product, 10)
	tx := gormDB.Where("category=?", category).Find(&products).Limit(10)
	if tx.Error != nil {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "查询错误"
		gormResponse.Data = tx.Error
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	gormResponse.Code = http.StatusOK
	gormResponse.Message = "查询成功"
	gormResponse.Data = products
	context.JSON(http.StatusOK, gormResponse)
}

在这里插入图片描述

func updateData(context *gin.Context) {
	errorTouch(context)
	var p Product
	err := context.Bind(&p)
	if err != nil {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "参数错误"
		gormResponse.Data = err
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	var count int64
	gormDB.Model(&Product{}).Where("number=?", p.Number).Count(&count)
	if count <= 0 {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "数据不存在"
		gormResponse.Data = "error"
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	tx := gormDB.Model(&Product{}).Where("number=?", p.Number).Updates(&p)
	if tx.RowsAffected <= 0 {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "写入失败"
		gormResponse.Data = "error"
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	gormResponse.Code = http.StatusOK
	gormResponse.Message = "更新成功"
	gormResponse.Data = "ok"
	context.JSON(http.StatusOK, gormResponse)
}

在这里插入图片描述

func delData(context *gin.Context) {
	errorTouch(context)
	number := context.Query("number")
	var count int64
	gormDB.Model(&Product{}).Where("number=?", number).Count(&count)
	if count <= 0 {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "数据不存在"
		gormResponse.Data = "error"
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	tx := gormDB.Where("number=?", number).Delete(&Product{})
	if tx.RowsAffected <= 0 {
		gormResponse.Code = http.StatusBadRequest
		gormResponse.Message = "删除失败"
		gormResponse.Data = "error"
		context.JSON(http.StatusOK, gormResponse)
		return
	}
	gormResponse.Code = http.StatusOK
	gormResponse.Message = "删除成功"
	gormResponse.Data = "ok"
	context.JSON(http.StatusOK, gormResponse)
}

在这里插入图片描述

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

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

相关文章

【leetcode2765--最长交替子数组】

要求&#xff1a;给定一个数组&#xff0c;找出符合【x, x1,x,x-1】这样循环的最大交替数组长度。 思路&#xff1a;用两层while循环&#xff0c;第一个while用来找到符合这个循环的开头位置&#xff0c;第二个用来找到该循环的结束位置&#xff0c;并比较一下max进行记录。 …

LLVM技术在GaussDB等数据库中的应用

目录 LLVM和数据库 LLVM适用场景 LLVM对所有类型的SQL都会有收益吗&#xff1f; LLVM在OLTP中就一定没有收益吗&#xff1f; GaussDB中的LLVM 1. LLVM在华为应用于数据库的时间线 2. GaussDB LLVM实现简析 3. GaussDB LLVM支持加速的场景 支持LLVM的表达式&#xff1a…

河南道路与桥梁乙级资质升级门槛条件解读

河南道路与桥梁乙级资质升级门槛条件解读如下&#xff1a; 一、企业基本条件 法人资格&#xff1a; 企业需具备独立企业法人资格&#xff0c;能够独立承担民事责任。注册资金&#xff1a; 企业的注册资金应不少于100万元人民币&#xff0c;这一数字直接体现了企业的经济实力和…

Yann LeCun 和 Elon Musk 就 AI 监管激烈交锋

&#x1f989; AI新闻 &#x1f680; Yann LeCun 和 Elon Musk 就 AI 监管激烈交锋 摘要&#xff1a;昨天&#xff0c;Yann LeCun 和Elon Musk 在社交媒体就人工智能的安全性和监管问题展开激烈辩论。LeCun 认为目前对 AI 的担忧和监管为时过早&#xff0c;主张开放和共享。而…

【linux:基础IO】

目录 系统调用的文件接口&#xff1a; open read: write: lseek: close: 系统调用的文件接口&#xff1a; open 当文件存在时&#xff1a;int open (const char*pathname,int flags)当文件不存在时&#xff1a;int open (const char* pathname,int flags,mode_t mode) 返…

拉格朗日插值法的推导

1、插值的基本定义   设函数 y f ( x ) yf(x) yf(x)在区间 [ a , b ] [a,b] [a,b]上有定义&#xff0c;且已知它在 n 1 n1 n1个互异点 a ≤ x 0 < x 1 < . . . < x n ≤ b a\leq x_0<x_1<...<x_n\leq b a≤x0​<x1​<...<xn​≤b上的函数值 y 0 …

经典文献阅读之--SMERF(通过标清导航地图增强车道感知和拓扑理解)

Tip: 如果你在进行深度学习、自动驾驶、模型推理、微调或AI绘画出图等任务&#xff0c;并且需要GPU资源&#xff0c;可以考虑使用Compshare的GPU算力云平台。他们提供高性价比的4090 GPU&#xff0c;按时收费每卡2.6元&#xff0c;月卡只需要1.7元每小时&#xff0c;并附带200G…

【全开源】西陆家政系统源码小程序(FastAdmin+ThinkPHP+原生微信小程序)

打造高效便捷的家政服务平台 一、引言&#xff1a;家政服务的数字化转型 随着人们生活节奏的加快&#xff0c;家政服务需求日益增长。为了满足广大用户对高效、便捷的家政服务的需求&#xff0c;家政小程序系统源码应运而生。这款源码不仅能够帮助家政服务提供商快速搭建自己…

【VTKExamples::Utilities】第十六期 WindowModifiedEvent

很高兴在雪易的CSDN遇见你 VTK技术爱好者 QQ:870202403 公众号:VTK忠粉 前言 本文分享VTK样例WindowModifiedEvent,希望对各位小伙伴有所帮助! 感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步! 你的点赞就是我的动力(^U^)ノ~YO 1. WindowModifi…

基于 RNNs 对 IMDB 电影评论进行情感分类

前言 系列专栏:【深度学习:算法项目实战】✨︎ 涉及医疗健康、财经金融、商业零售、食品饮料、运动健身、交通运输、环境科学、社交媒体以及文本和图像处理等诸多领域,讨论了各种复杂的深度神经网络思想,如卷积神经网络、循环神经网络、生成对抗网络、门控循环单元、长短期记…

Sqli-labs-master靶场1-20通关教程

目录 SQL注入基本语句 Less-1&#xff08;字符型-闭合 &#xff09; Less-2&#xff08;数字型&#xff09; Less-3&#xff08;字符型-闭合 ) &#xff09; Less-4&#xff08;字符型-闭合 ") &#xff09; Less-5&#xff08;报错注入-闭合 &#xff09; Less-…

实战教程:使用Go的net/http/fcgi包打造高性能Web应用

实战教程&#xff1a;使用Go的net/http/fcgi包打造高性能Web应用 简介理解FCGI协议FastCGI工作原理CGI与FastCGI对比其他接口对比 初步使用net/http/fcgi包设置和配置基础环境一个简单的FastCGI应用示例本地测试与调试 深入net/http/fcgi包的高级用法探索net/http/fcgi的主要功…

【贪心算法】C++ 解决算法题:买卖股票 / K次取反 / 按身高排序 / 优势洗牌

1. 前言 1.1 贪心算法介绍 贪心算法&#xff08;Greedy Algorithm&#xff09;是一种在每一步选择中都采取当前状态下最优决策的算法。贪心算法通常用来解决最优化问题&#xff0c;其核心思想是通过局部最优解逐步推导出全局最优解。 在贪心算法中&#xff0c;我们并不总是考…

探索电商ERP平台的功能架构:实现高效运营的关键

在当今数字化时代&#xff0c;电子商务已经成为了商业运营的主流模式之一。为了应对日益激烈的市场竞争&#xff0c;企业需要借助先进的技术工具来提高运营效率和管理能力。在这篇博客中&#xff0c;我们将深入探讨电商ERP平台的功能架构&#xff0c;揭示其如何成为实现高效运营…

港科夜闻|香港科大与利丰成立供应链研究院,应对多变商业环境中的挑战与机遇...

关注并星标 每周阅读港科夜闻 建立新视野 开启新思维 1、香港科大与利丰成立供应链研究院&#xff0c;应对多变商业环境中的挑战与机遇。该研究院的成立&#xff0c;旨在推动全球供应链管理的研究与创新商业模式。研究院结合香港科大卓越研究实力及利丰于供应链管理方面的深厚行…

Dify快速接入微信

一、Dify简介 项目官网&#xff1a;Dify.AI 生成式 AI 应用创新引擎 Dify 是一款开源的大语言模型(LLM) 应用开发平台。它融合了后端即服务&#xff08;Backend as Service&#xff09;和 LLMOps 的理念&#xff0c;使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非…

【管理咨询宝藏116】某大型国有集团公司战略落地保障方案

本报告首发于公号“管理咨询宝藏”&#xff0c;如需阅读完整版报告内容&#xff0c;请查阅公号“管理咨询宝藏”。 【管理咨询宝藏116】某大型国有集团公司战略落地保障方案 【格式】PDF版本 【关键词】战略落地、大型国企、战略报告 【核心观点】 - 资产规模以提高资产质量、…

halcon SVM 缺陷检测分类

一、概述 训练数据 二、算子解释 compactness Halcon 算子 compactness_halcon compactness-CSDN博客 *计算输入区域的紧凑度 compactness (Region, Compactness) 原理解释 convexity 每个输入区域的凸度 Halcon 算子 convexity_halcon convexity-CSDN博客 *计算每个输…

如何关闭MySQL凌晨12点自动弹窗?

要关闭 MySQL 在凌晨 12 点自动弹窗的行为&#xff0c;首先需要确定弹窗的具体原因。 打开“任务计划程序”&#xff1a; 按 Win R&#xff0c;输入 taskschd.msc&#xff0c;然后按 Enter。 在左侧导航栏中&#xff0c;选择“任务计划程序库”。 查找与 MySQL 相关的任务&…

12-常用类

1. 包装类 针对八种基本数据类型封装的相应的引用类型。 有了类的特点&#xff0c;就可以调用类中的方法。&#xff08;为什么要封装&#xff09; 基本数据类型包装类booleanBooleanchar CharacterbyteByteshortShortintIntegerlongLongfloatFloatdoubleDouble 1.1 …