本文为大家分享了java+vue实现添加选择题到题库功能的具体代码,供大家参考,具体内容如下
做个备份
数据库表:


后台接口
@DeleteMapping("deleteQuestion")
@ApiOperation(value = "删除问题")
public ServerResponse deleteQuestion(Integer id){
sysQuestionMapper.deleteByPrimaryKey(id);
sysQuestionAnswerMapper.deleteByQUestionId(id);
return ServerResponse.createBySuccess("删除成功");
}
@GetMapping("getQuestionList")
@ApiOperation(value = "获得问题列表")
public ServerResponse getQuestionList(){
List list = sysQuestionMapper.selectAllQuestion();
return ServerResponse.createBySuccess(list);
}
@GetMapping("getQuestionAnswerList")
@ApiOperation(value = "获得问题选项列表")
public ServerResponse getQuestionAnswerList(Integer question_id){
List list = sysQuestionAnswerMapper.selectByQuestionId(question_id);
return ServerResponse.createBySuccess(list);
}
@PostMapping("addQuestion")
@ApiOperation(value = "添加问题")
public ServerResponse addQuestion(String question,String[] answerList,Integer[] answer){
Integer type = 1;
if (answer.length != 1) {
type = 2;
}
String stringAnswer = "";
List list = Arrays.asList(answer);
SysQuestion sysQuestion = new SysQuestion();
sysQuestion.setQuestionName(question);
sysQuestion.setCreateTime(new Date());
sysQuestion.setType(type);
sysQuestionMapper.insert(sysQuestion);
Integer question_id = sysQuestionMapper.selectLastQuestionId();
for (int i=0;i
代码中涉及的sql语句
select max(id) from sys_question select * from sys_question order by create_time desc
select * from sys_question_answer
where question_id=#{question_id}
select max(id) from sys_question_answer
delete from sys_question_answer where question_id=#{question_id}
vue页面