当前位置: 首页 > news >正文

微服务项目->在线oj系统(Java-Spring)-后台管理(2)

题库管理

表结构设计

从图表中我们可以看到:

我们需要题目id(唯一),所以我们可以将question_id作为主键

题目标题(字符串)、题目难度(这里用1,2,3表示不同难度,前端统一处理)

创建人(int),创建时间(datetime),当然同理,我们数据库里面也要存修改人和修改时间来增加安全保障

当我们想要添加题目

我们需要题目,难度,时间限制(int)和空间限制(int),题目用例(字符串【json字符串】),默认代码块(字符串),main函数(字符串)

综上,我们可以创建如下表结构:

create table tb_question(
question_id bigint unsigned not null comment '题目id',
title varchar(50) not null  comment '题目标题',
difficulty tinyint not null comment '题目难度1:简单  2: 中等 3: 困难',
time_limit int not null comment '时间限制',
space_limit int not null comment '空间限制',
content varchar(1000) not null comment '题目内容',
question_case varchar(1000)  comment '题目用例',
default_code varchar(500) not null comment '默认代码块',
main_fuc varchar(500) not null comment 'main函数',
create_by    bigint unsigned not null  comment '创建人',
create_time  datetime not null comment '创建时间',
update_by    bigint unsigned  comment '更新人',
update_time  datetime comment '更新时间',
primary key(`question_id`)
);

创建实体类(Entity)

使用雪花id来确保主键

@TableName("tb_question")
@Data
public class Question extends BaseEntity {@TableId(type = IdType.ASSIGN_ID)private Long questionId;private String title;private Integer difficulty;private Long timeLimit;private Long spaceLimit;private String content;private String questionCase;private String defaultCode;private String mainFuc;
}

创建前端VO

当我们查询的时候,我们需要给前端返回问题ID,问题标题,问题难度,创建人,创建时间

所以下出如下代码

@Data
public class QuestionVO {private Long questionId;private String title;private Integer difficulty;private String createName;private LocalDateTime createTime;
}

创建接受前端类(DTO)

当我们在前端搜索的时候,我们需要给后端传递筛选参数以及页数:

我们需要传递难度,标题,第几页,每页几个

@Getter
@Setter
public class QuestionQueryDTO  {private Integer difficulty;private String title;private  Integer pageSize=10;private  Integer pageNum=1;
}

专属返回结果

我们需要给前端返回值:告诉前端状况:

总数目,题目列表,响应状态码,响应消息

import com.bite.common.core.enums.ResultCode;
import lombok.Getter;
import lombok.Setter;import java.util.ArrayList;
import java.util.List;@Getter
@Setter
public class TableDataInfo {/*** 总记录数*/private long total;/*** 列表数据*/private List<?> rows;/*** 消息状态码*/private int code;/*** 消息内容*/private String msg;/*** 表格数据对象*/public TableDataInfo() {}//未查出任何数据时调用public static TableDataInfo empty() {TableDataInfo rspData = new TableDataInfo();rspData.setCode(ResultCode.SUCCESS.getCode());rspData.setRows(new ArrayList<>());rspData.setMsg(ResultCode.SUCCESS.getMsg());rspData.setTotal(0);return rspData;}//查出数据时调用public static TableDataInfo success(List<?> list,long total) {TableDataInfo rspData = new TableDataInfo();rspData.setCode(ResultCode.SUCCESS.getCode());rspData.setRows(list);rspData.setMsg(ResultCode.SUCCESS.getMsg());rspData.setTotal(total);return rspData;}
}

Controller类

@RestController
@RequestMapping("/question")
@Tag(name = "题目管理接口")
public class QuestionController extends BaseController {@Autowiredprivate IQuestionService questionService;@GetMapping("/list")public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {return questionService.list(questionQueryDTO);}
}

Service类

我们从数据库中取出所需的题目列表,然后进行判断,如果不为空,则进行封装为TableDataInfo类

Mapper类

由于我们的查询条件较多,所以我们这里不使用Mybatis-plus提供的类,使用原始的xml方式

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bite.system.mapper.question.QuestionMapper"><select id="selectQuestionList" resultType="com.bite.system.model.question.vo.QuestionVO">SELECTtq.question_id,tq.title,tq.difficulty,ts.nick_name as create_name,tq.create_timeFROMtb_question tqleft jointb_sys_user tsontq.create_by = ts.user_id<where><if test="difficulty !=null ">AND difficulty = #{difficulty}</if><if test="title !=null and title !='' ">AND title LIKE CONCAT('%',#{title},'%')</if><if test="excludeIdSet !=null and !excludeIdSet.isEmpty()"><foreach collection="excludeIdSet" open=" AND tq.question_id NOT IN( " close=" ) " item="id" separator=",">#{id}</foreach></if></where>ORDER BYcreate_time DESC</select>
</mapper>

我们这里使用了联合查询,因为我们创建题库表的时候,只有创建人,但是没有匿称

剩下的就是我们之前学的一些查询语句

http://www.dtcms.com/a/418706.html

相关文章:

  • 【MySQL体系】第2篇:MySQL索引类型和原理
  • flash型的著名网站网站开发公司怎么接单
  • 【第五章:计算机视觉-项目实战之图像分割实战】2.图像分割实战:人像抠图-(1)人像抠图Image Matting算法详解
  • 使用 PyTorch 构建并训练 CNN 模型
  • 如何做电影网站狼视听seo外包优化服务商
  • blender布局工作区突然变得很卡
  • 【计算机视觉】图像去雾技术
  • 工信部网站icp备案号文艺范wordpress主题
  • 树莓派无法播放哔哩哔哩等视频
  • 华为芯片泄密案警示:用Curtain e-locker阻断内部数据泄露
  • 记一次达梦数据库的查询异常
  • 泸州市建设工程管理局网站58网站怎么做品牌推广
  • 个人主题网站设计论文北京seo推广系统
  • AI编程开发系统001-基于SpringBoot+Vue的旅游民宿租赁系统
  • 通用人工智能(AGI):从技术探索到社会重构的 2025 展望
  • 【Web前端|第五篇】Vue进阶(一):Axios工具和前端工程化
  • RISE论文阅读
  • LeetCode 416 分割等和子集
  • web开发,在线%车辆管理%系统,基于Idea,html,css,vue,java,springboot,mysql
  • 《安富莱嵌入式周报》第358期:USB4雷电开源示波器,2GHz带宽,3.2Gsps采样率,开源亚微米级精度3D运动控制平台,沉浸式8声道全景声音频录制
  • Axure: 多级多选可交互树状列表
  • 打破线制,告别电脑:积木易搭发布无线一体式3D扫描仪Toucan
  • 做电影网站的资源从哪里换wordpress新建音乐界面
  • Conda环境激活全指南:bash、conda activate与source activate详解
  • 英国网站后缀爱做的小说网站吗
  • 第四部分:VTK常用类详解(第98章 vtkBalloonWidget气球控件类)
  • Git 应用与规范指南
  • 查网站 备案信息有没有好的网站可以学做头发
  • Leetcode 14. 最长公共前缀
  • 在 Windows 上安装 WSL 并配置 SSH 服务,让 FinalShell 连接 Ubuntu