1. 实体类环境
题目
package co.yixiang.exam.entity;
import co.yixiang.domain.BaseDomain;
import co.yixiang.exam.config.CustomStringListDeserializer;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.List;
/***
* 题库表
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ExQuestion extends BaseDomain {
@JsonCreator
public ExQuestion(String someValue) {
// 初始化代码
}
// 主键
private Integer id;
// 题目序号
private Integer questionNum;
// 父题目id
private Integer pid;
// 考试题目
private String questionTitle;
// 考试子题目
private String questionTitleZi;
// 正确答案
private String optionsCorrect;
// 分数
private Integer questionScore;
// 答案解析
private String questionAnswer;
// 分类科目:初级会计,经济基础
private String questionSubject;
// 考题类型:1.单选题,2.多选题,3.判断题,4.不定项选择题
private String questionType;
// 创建人
private String createBy;
// 修改人
private String updateBy;
// 前端校验
@TableField(exist = false)
private boolean launch = false;
// 选项表内容id 集合
@TableField(exist = false)
private List<Integer> ids;
//子选项内容
@TableField(exist = false)
private List<ExOptions> exOptions;
@TableField(exist = false)
private List<ExQuestion> exQuestionDtoList; // 子菜单列表
@TableField(exist = false)
private List<String> answerList;
@TableField(exist = false)
private List<Integer> questionIds;
}
选项
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExOptions extends BaseDomain {
// 题目选项ID(自增)
private Integer id;
// 题库序号
private Integer optionsNum;
// exam_question考题表的ID
private Integer questionId;
// 选项内容
private String optionsContent;
// 创建人
private String createBy;
// 修改人
private String updateBy;
@TableField(exist = false)
private String option;
}
vo返回类
@Data
public class QuestionOptionsTestVo {
private Integer id;
// 考试题目
private String questionTitle;
// 考试子题目
private String questionTitleZi;
//子选项内容
@TableField(exist = false)
private List<ExOptions> exOptions;
}
2.语法案例
public List<QuestionOptionsTestVo> getQuestionOptions() {
MPJLambdaWrapper<ExQuestion> wrapper = new MPJLambdaWrapper<>();
// 主表指定查询id和题目
wrapper.select(ExQuestion::getId)
.select(ExQuestion::getQuestionTitle)
.select(ExQuestion::getQuestionTitleZi)
// 左连接选项
.leftJoin(ExOptions.class, ExOptions::getQuestionId, ExQuestion::getId)
// 选项放进exOptions集合
.selectCollection(ExOptions.class, ExQuestion::getExOptions);
List<QuestionOptionsTestVo> questionOptionsTestVos = exQuestionMapper.selectJoinList(QuestionOptionsTestVo.class, wrapper);
return questionOptionsTestVos;
}