前言:大二刚开始接手了本学院的oj,并管理了一段时间,后来老师给我说我可以开发一个 oj 用来当做毕设。
我:嗯…(知道开发一个比较困难)
来来回回最终下定决心开始了 oj 的开发,由于我都是略懂一点(这个最难受了),所以做起来比较困难,也没有什么人可以请教,只能自己一点一点的找网上的。
在我管理的 oj 中,使用 php 开发的,但是但是,我学的主要的是 java 因此想写一个 java 版本的。在之前,学长接手的时候对于本学院 oj 项目的记录可以说是为零,虽然在我接手的时候不敢说是一片空白,但是也差不多 (>_<) ,经历了一个学期,基本摸清了项目的主要结构,并对项目的一些 bug 进行修改,比如:限制同一账号同时登录多个;补充了对于用户的删除(彻底的),后面的修改 id(这个是 primary key)还没有写,准备带着下一届的学弟开发(因为我也要转手了)。不足的:还没有了解他的判题机制(当时也是 十分茫然、无助。。。。)还可以的:对项目主要结构写了自认为可以的解析文档,对以后的开发确定的大致的方向,并留下一些开发经验
在此之前听了 dl 学长的建议使用 docker进行环境的部署,经过好长时间的尝试,还是在 win11 中进行了安装,因为用了好长时间,工具比较全,也不想在去弄别的了。注:Win11 家庭版可以安装 docker !!! 简单使用还是可以的(对我目前的需求来讲)
使用主要工具:idea 2023docker 25.0.6(win版)vsCode
使用主要框架springBoot 2.6.11
在进行Maven引用或注解引用的时候,一定考虑版本适配问题(刚开始没注意springboot版本适配问题,一直报错)
如何使用多模块开发,可以自己参考其他的
org.springframework.boot spring-boot-starter-mail mysql mysql-connector-java 8.0.32 org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test com.github.oshi oshi-core 6.4.0 com.alibaba fastjson 2.0.35 org.quartz-scheduler quartz 2.3.2 com.alibaba druid-spring-boot-starter 1.2.16 org.springframework.boot spring-boot-starter-websocket cn.hutool hutool-all 5.8.26 com.baomidou mybatis-plus-boot-starter 3.5.6 org.springframework.boot spring-boot-configuration-processor true io.netty netty-all 4.1.25.Final com.auth0 java-jwt 3.10.3 junit junit test org.dom4j dom4j 2.1.4 org.json json 20220924 org.springframework.boot spring-boot-starter-data-redis redis.clients jedis io.lettuce lettuce-core redis.clients jedis nz.ac.waikato.cms.weka weka-stable 3.8.6 io.minio minio 8.2.2 io.springfox springfox-boot-starter 3.0.0 刚开始可以只写一个空的Swagger2Config 类,注意在启动类上加上@EnableSwagger2 @EnableWebMvc注解
对于 swagger 的使用可以自行学习
接口文档地址:http://localhost:8080/swagger-ui/index.html#/ (注意本项目的根路径为 /)
@Configuration @EnableSwagger2 @EnableWebMvc public class Swagger2Config { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .enable(true).groupName("判题测试接口").tags(new Tag("judge相关接口", "ee")) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.ant("/judge/**")) .build(); } @Bean public Docket api01(){ return new Docket(DocumentationType.SWAGGER_2) .enable(true) .groupName("user管理接口") .tags(new Tag("用户管理相关接口","Test01Controller")) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.ant("/user/**")) .build() ; } // //构建 api文档的详细信息函数 // private ApiInfo apiInfo() { // return new ApiInfoBuilder() // //页面标题 // .title("XX平台API接口文档") // //创建人 // .contact(new Contact("冯冬冬", "http://www.javachat.cc", // "3049352171@qq.com")) // //版本号 // .version("1.0") // //描述 // .description("系统API描述") // .build(); // } } 主要是使用docker镜像拉取环境,每次判题的时候新建容器,结束后删除容器
镜像配置:
{ "builder": { "gc": { "defaultKeepStorage": "20GB", "enabled": true } }, "experimental": false, "features": { "buildkit": true }, "registry-mirrors": [ "https://do.nark.eu.org", "https://dc.j8.work", "https://docker.m.daocloud.io", "https://dockerproxy.com", "https://docker.mirrors.ustc.edu.cn", "https://docker.nju.edu.cn" ] }