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

网友投稿 349 2023-01-10


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

本文为大家分享了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

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 list = Arrays.asList(answer);

sysQuestionAnswerMapper.deleteByQUestionId(question_id);

for (int i=0;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;

}

}

stringAnswer = stringAnswer.substring(1,stringAnswer.length());

SysQuestion sysQuestion1 = sysQuestionMapper.selectByPrimaryKey(question_id);

sysQuestion1.setAnswerId(stringAnswer);

sysQuestion1.setQuestionName(question);

sysQuestion1.setType(type);

sysQuestion1.setUpdateTime(new Date());

sysQuestionMapper.updateByPrimaryKey(sysQuestion1);

return ServerResponse.createBySuccess("更新成功");

}

代码中涉及的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页面

添加

删除

v-for="(domain, index) in dynamicValidateForm.domains"

:key="domain.key"

:label="'选项' + (index + 1)"

:value="index">

提交

新增选项

清空

:data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe style=" width: 100%"

:default-sort="{prop: 'id',order: 'descending'}">

:rows="2"

placeholder="请输入内容"

v-model="scope.row.questionName">

更新

删除

@size-change="handleSizeChange"

@current-change="handleCurrentChange"

:current-page="currentPage"

:page-sizes="[10, 20, 50, 100]"

:page-size="pagesize"

layout="total, sizes, prev, pager, next, jumper"

:total="tableData.length">

实现效果:

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 list = Arrays.asList(answer);

sysQuestionAnswerMapper.deleteByQUestionId(question_id);

for (int i=0;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;

}

}

stringAnswer = stringAnswer.substring(1,stringAnswer.length());

SysQuestion sysQuestion1 = sysQuestionMapper.selectByPrimaryKey(question_id);

sysQuestion1.setAnswerId(stringAnswer);

sysQuestion1.setQuestionName(question);

sysQuestion1.setType(type);

sysQuestion1.setUpdateTime(new Date());

sysQuestionMapper.updateByPrimaryKey(sysQuestion1);

return ServerResponse.createBySuccess("更新成功");

}

代码中涉及的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页面

添加

删除

v-for="(domain, index) in dynamicValidateForm.domains"

:key="domain.key"

:label="'选项' + (index + 1)"

:value="index">

提交

新增选项

清空

:data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe style=" width: 100%"

:default-sort="{prop: 'id',order: 'descending'}">

:rows="2"

placeholder="请输入内容"

v-model="scope.row.questionName">

更新

删除

@size-change="handleSizeChange"

@current-change="handleCurrentChange"

:current-page="currentPage"

:page-sizes="[10, 20, 50, 100]"

:page-size="pagesize"

layout="total, sizes, prev, pager, next, jumper"

:total="tableData.length">

实现效果:

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;

}

}

stringAnswer = stringAnswer.substring(1,stringAnswer.length());

SysQuestion sysQuestion1 = sysQuestionMapper.selectByPrimaryKey(question_id);

sysQuestion1.setAnswerId(stringAnswer);

sysQuestion1.setQuestionName(question);

sysQuestion1.setType(type);

sysQuestion1.setUpdateTime(new Date());

sysQuestionMapper.updateByPrimaryKey(sysQuestion1);

return ServerResponse.createBySuccess("更新成功");

}

代码中涉及的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页面

添加

删除

v-for="(domain, index) in dynamicValidateForm.domains"

:key="domain.key"

:label="'选项' + (index + 1)"

:value="index">

v-for="(domain, index) in dynamicValidateForm.domains"

:key="domain.key"

:label="'选项' + (index + 1)"

:value="index">

提交

新增选项

清空

:data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe style=" width: 100%"

:default-sort="{prop: 'id',order: 'descending'}">

:rows="2"

placeholder="请输入内容"

v-model="scope.row.questionName">

更新

删除

:data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe style=" width: 100%"

:default-sort="{prop: 'id',order: 'descending'}">

:rows="2"

placeholder="请输入内容"

v-model="scope.row.questionName">

:rows="2"

placeholder="请输入内容"

v-model="scope.row.questionName">

更新

删除

@size-change="handleSizeChange"

@current-change="handleCurrentChange"

:current-page="currentPage"

:page-sizes="[10, 20, 50, 100]"

:page-size="pagesize"

layout="total, sizes, prev, pager, next, jumper"

:total="tableData.length">

@size-change="handleSizeChange"

@current-change="handleCurrentChange"

:current-page="currentPage"

:page-sizes="[10, 20, 50, 100]"

:page-size="pagesize"

layout="total, sizes, prev, pager, next, jumper"

:total="tableData.length">

实现效果:


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:子类继承父类并实现接口(Java子类继承父类)
下一篇:浅谈JAVA8给我带了什么——流的概念和收集器
相关文章

 发表评论

暂时没有评论,来抢沙发吧~