vue+java实现添加单选题多选题到题库功能

做个备份

数据库表:
在这里插入图片描述在这里插入图片描述后台接口

@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<SysQuestion> list = sysQuestionMapper.selectAllQuestion();
        return ServerResponse.createBySuccess(list);
    }

    @GetMapping("getQuestionAnswerList")
    @ApiOperation(value = "获得问题选项列表")
    public ServerResponse getQuestionAnswerList(Integer question_id){
        List<SysQuestionAnswer> 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<Integer> 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<answerList.length;i++){
            SysQuestionAnswer sysQuestionAnswer = new SysQuestionAnswer();
            sysQuestionAnswer.setAnswer(answerList[i]);
            sysQuestionAnswer.setQuestionId(question_id);
            sysQuestionAnswerMapper.insert(sysQuestionAnswer);
            Integer answer_id = sysQuestionAnswerMapper.selectLastAnswerId();
            if (list.contains(i)) {
                stringAnswer = stringAnswer + "," + answer_id;
            }
        }
        System.out.println(stringAnswer);
        stringAnswer = stringAnswer.substring(1,stringAnswer.length());
        System.out.println(stringAnswer);
        SysQuestion sysQuestion1 = sysQuestionMapper.selectByPrimaryKey(question_id);
        sysQuestion1.setAnswerId(stringAnswer);
        sysQuestionMapper.updateByPrimaryKey(sysQuestion1);
        return ServerResponse.createBySuccess("创建成功");
    }

    @PostMapping("updateQuestion")
    @ApiOperation(value = "更新问题")
    public ServerResponse updateQuestion(Integer question_id,String question,String[] answerList,Integer[] answer){
        Integer type = 1;
        if (answer.length != 1) {
            type = 2;
        }
        String stringAnswer = "";
        List<Integer> list = Arrays.asList(answer);
        sysQuestionAns
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值