当前位置:网站首页>基于Gin、Gorm实现的在线练习系统之项目梳理
基于Gin、Gorm实现的在线练习系统之项目梳理
2022-06-11 00:47:00 【JIeJaitt】
go/gin/gorm/mysql等环境搭建略过;首先使用Navicat新建一个数据库gin_gorm_online_judge用于本项目,内容如下图:
在本库中新建问题表problem如下图:
我们正常的项目逻辑(项目流程)应该是我们定义完一张表之后我们需要去我们的gorm里面把它的 model也给它同步过去;
我们在Goland新建目录models目录,然后新建problem.go文件如下所示:
problem.go内容如下:
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"
}
新建user表如下:
新建 user.go如下:
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"
}
新建category表:
新建category.go文件:
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"
}
新建submit表:
新建submit.go文件如下:
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"
}
整体构建完后目录如下:
边栏推荐
- How to download web photos
- 1.3 introduction to ROS UAV
- MATLAB数组其他常见操作笔记
- Threejs: pit encountered in drawing Bessel curve with two-point coordinates
- PX4装机教程(六)垂起固定翼(倾转)
- Garbled code when the command parameter contains% in VisualStudio debugging
- 【HaaS Hands-On】全新视频节目上线 创意案例我们一起上手做 第一期E01: 物联网工程师 和你一起上手做遥控机械臂
- Once you know these treasure websites, you can't live without them!!!
- Loki 学习总结(1)—— Loki 中小项目日志系统的不二之选
- [leetcode] intersecting linked list
猜你喜欢

threejs:如何获得几何体的boundingBox?

On permutation and combination in probability and statistics

关于概率统计中的排列组合

Daily problem essay | 21.11.29: use resttemplate to call external put request, and prompt '400 bad request'

2.2、ROS+PX4仿真多点巡航飞行----正方形

今日睡眠质量记录80分

關於概率統計中的排列組合

flutter 状态管理

【错误记录】Android 应用安全检测漏洞修复 ( StrandHogg 漏洞 | 设置 Activity 组件 android:taskAffinity=““ )

2021-2-14 gephi learning notes
随机推荐
Leetcode 1116 print zero even odd (concurrent multithreading countdownlatch lock condition)
逻辑漏洞 / 业务漏洞
卡尔曼滤波(KF)、拓展卡尔曼滤波(EKF)推导
Leetcode divide and conquer method
threejs:流光效果封装
C语言 深度探究具有不定参数的函数
ACM教程 - 堆排序
2.1、ROS+PX4仿真---定点飞行控制
kubernetes 二进制安装(v1.20.15)(七)加塞一个工作节点
[chess life] 01 life is like chess
Px4 from abandonment to mastery (twenty four): customized model
今日睡眠质量记录80分
Leetcode 652 find duplicate subtrees (recommended by DFS)
1.5、PX4载具选择
China-open-ssl编译的一些记录
关于CS-3120舵机使用过程中感觉反应慢的问题
Garbled code when the command parameter contains% in VisualStudio debugging
2022.6.6-----leetcode.732
MATLAB随机函数汇总
1.4PX4程序下载