master
修改密码漏洞修复完成 8 months ago
parent b7a8b6f0e6
commit 0080cc0683

@ -4,7 +4,12 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="9f8c3ce4-c378-4191-b7a4-3d5acbc0ebbc" name="Changes" comment="rrddf" />
<list default="true" id="9f8c3ce4-c378-4191-b7a4-3d5acbc0ebbc" name="Changes" comment="rrddf">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/models/Order.go" beforeDir="false" afterPath="$PROJECT_DIR$/models/Order.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/models/User.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/mydb/initialize.go" beforeDir="false" afterPath="$PROJECT_DIR$/mydb/initialize.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />

@ -10,7 +10,6 @@ type Order struct {
ID uint
OrderNumber string
TotalAmount float64
UserID uint // 外键
//User User `gorm:"foreignKey:UserID"` // 一对一关联,通过 UserID 外键关联到 User 结构体
}
@ -28,7 +27,7 @@ func (Order) TableName() string {
func SaveOrder() {
uuid := uuid.New()
// 创建记录
order := Order{OrderNumber: uuid.String(), TotalAmount: 1999.9, UserID: 1}
order := Order{OrderNumber: uuid.String(), TotalAmount: 1999.9}
result := mydb.DB.Create(&order)
if result.Error != nil {
fmt.Println("Failed to create order:", result.Error)

@ -1,47 +0,0 @@
package models
import (
"fmt"
"go_mqtt/mydb"
"gorm.io/gorm"
)
//gorm:"column:column_name":指定字段在数据库中的列名。
//gorm:"primaryKey":指定字段为主键。
//gorm:"autoIncrement":指定字段为自增长。
//gorm:"unique":指定字段在数据库中唯一。
//gorm:"not null":指定字段不能为空。
//gorm:"default:value":指定字段的默认值。
//gorm:"size:length":指定字段的长度。
//gorm:"index":指定字段创建索引。
type User struct {
gorm.Model // 内置模型结构体,包含 ID、CreatedAt、UpdatedAt、DeletedAt 字段
Name string
Age int
Email string `gorm:"unique"` // 使用标签指定字段属性,这里表示 Email 字段在数据库中是唯一的
Address string
Order Order // 一对一关联,一个用户对应一个订单
}
func init() {
fmt.Println("User init()")
mydb.DB.AutoMigrate(&User{})
}
// TableName 会将 User 的表名重写为 `user`
func (User) TableName() string {
return "user"
}
func SaveUser(uuid string) {
// 创建记录
product := User{Name: "Wenfei", Age: 20, Email: uuid, Address: "天等县弄在屯"}
result := mydb.DB.Create(&product)
if result.Error != nil {
fmt.Println("Failed to create product:", result.Error)
} else {
fmt.Println("User created successfully!")
}
}

@ -19,8 +19,8 @@ func initDatabase() {
//dsn := "root:Skyinno251,@tcp(192.168.2.18:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local"
//dsn := "root:Skyinno251,@tcp(47.242.184.139:3306)/appserver?charset=utf8mb4&parseTime=True&loc=Local"
dsn := "root:Skyinno251,@tcp(localhost:3306)/appserver?charset=utf8mb4&parseTime=True&loc=Local"
//dsn := "root:Skyinno251,@tcp(192.168.3.29:3306)/appserver?charset=utf8mb4&parseTime=True&loc=Local"
//dsn := "root:Skyinno251,@tcp(localhost:3306)/appserver?charset=utf8mb4&parseTime=True&loc=Local"
dsn := "root:Skyinno251,@tcp(192.168.3.29:3306)/appserver?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.New(mysql.Config{
DSN: dsn, // DSN data source name

Loading…
Cancel
Save