当前位置:网站首页>Project sorting of Online Exercise System Based on gin and Gorm

Project sorting of Online Exercise System Based on gin and Gorm

2022-06-11 01:57:00 JIeJaitt

go/gin/gorm/mysql Wait for the environment to be built ; use first Navicat Create a new database gin_gorm_online_judge For this project , The contents are as follows: :
 Insert picture description here
Create a new question table in this library problem Here's the picture :
 Insert picture description here

Our normal project logic ( Project process ) It should be that after we define a table, we need to go to our gorm Put it in there model Also sync it to the past ;

We are Goland new directory models Catalog , Then build problem.go The file is shown below :
 Insert picture description here
problem.go The contents are as follows :

package models

import "gorm.io/gorm"

type Problem struct {
    
	gorm.Model
	Identity   string `gorm:"column:identity;type:varchar(36);" json:"identity"`
	CategoryId string `gorm:"column:category_id;type:varchar(255);" json:"category-id"`
	Title      string `gorm:"column:title;type:varchar(255)" json:"title"`
	Content    string `gorm:"column:content;type:text" json:"content"`
	MaxRuntime int    `gorm:"column:max_runtime;type:int(11);" json:"max-runtime"`
	MaxMem     int    `gorm:"column:max_mem;type:int(11);" json:"max_mem"`
}

func (table *Problem) TableName() string {
    
	return "problem"
}

newly build user The table is as follows :
 Insert picture description here

newly build user.go as follows :

package models

import "gorm.io/gorm"

type User struct {
    
	gorm.Model
	Identity string `gorm:"column:identity;type:varchar(36);" json:"identity"`
	Name     string `gorm:"column:name;type:varchar(100)" json:"name"`
	Password string `gorm:"column:password;type:varchar(32)" json:"password"`
	Phone    string `gorm:"column:phone;type:varchar(20)" json:"phone"`
	Mail     string `gorm:"column:mail;type:varchar(100)" json:"mail"`
}

func (table *User) TableName() string {
    
	return "user"
}

newly build category surface :
 Insert picture description here
newly build category.go file :

package models

import "gorm.io/gorm"

type Category struct {
    
	gorm.Model
	Identity string `gorm:"column:identity;type:varchar(36);" json:"identity"`
	Name     string `gorm:"column:name;type:varchar(100);" json:"name"`
	ParentId int    `gorm:"column:parent_id;type:int(11);" json:"parent_id"`
}

func (table *Category) TableName() string {
    
	return "category"
}

newly build submit surface :
 Insert picture description here
newly build submit.go The documents are as follows :

package models

import "gorm.io/gorm"

type Submit struct {
    
	gorm.Model
	Identity        string `gorm:"column:identity;type:varchar(36);" json:"identity"`
	ProblemIdentity string `gorm:"column:problem_identity;type:varchar(36)" json:"problem_identity"`
	UserIdentity    string `gorm:"column:user_identity;type:varchar(36)" json:"user_identity"`
	Path            string `gorm:"column:path;type:varchar(20)" json:"path"`
}

func (table *Submit) TableName() string {
    
	return "submit"
}

After the overall construction, the directory is as follows :
 Insert picture description here

原网站

版权声明
本文为[JIeJaitt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110047039422.html