日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

spring boot實現自動輸出word文檔功能的實例代碼

瀏覽:193日期:2022-06-24 14:20:25

spring boot實現自動輸出word文檔功能

本文用到Apache POI組件組件依賴在pom.xml文件中添加

<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.0</version></dependency><dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.0</version></dependency>

首先創建相關的實體類、編寫需要用到的sql查詢。

import lombok.Data;// 選擇題實體@Datapublic class MultiQuestion { private Integer questionId; private String subject; private String section; private String answerA; private String answerB; private String answerC; private String answerD; private String question; private String level; private String rightAnswer; private String analysis; //題目解析 private Integer score; }

import lombok.Data;//填空題實體類@Datapublic class FillQuestion { private Integer questionId; private String subject; private String question; private String answer; private Integer score; private String level; private String section; private String analysis; //題目解析 }

import lombok.Data;//判斷題實體類@Datapublic class JudgeQuestion { private Integer questionId; private String subject; private String question; private String answer; private String level; private String section; private Integer score; private String analysis; //題目解析}

創建好要用到的實體類之后,利用mybatis寫sql查詢,可以分為兩種:1、配置mapper.xml文件路徑,在xml文件中編寫sql語句。2、直接使用注解。本文使用方法為第二種。

@Mapperpublic interface MultiQuestionMapper { /** * select * from multiquestions where questionId in ( * select questionId from papermanage where questionType = 1 and paperId = 1001 * ) */ @Select('select * from multi_question where questionId in (select questionId from paper_manage where questionType = 1 and paperId = #{paperId})') List<MultiQuestion> findByIdAndType(Integer PaperId); @Select('select * from multi_question') IPage<MultiQuestion> findAll(Page page); /** * 查詢最后一條記錄的questionId * @return MultiQuestion */ @Select('select questionId from multi_question order by questionId desc limit 1') MultiQuestion findOnlyQuestionId(); @Options(useGeneratedKeys = true,keyProperty = 'questionId') @Insert('insert into multi_question(subject,question,answerA,answerB,answerC,answerD,rightAnswer,analysis,section,level) ' + 'values(#{subject},#{question},#{answerA},#{answerB},#{answerC},#{answerD},#{rightAnswer},#{analysis},#{section},#{level})') int add(MultiQuestion multiQuestion); @Select('select questionId from multi_question where subject =#{subject} order by rand() desc limit #{pageNo}') List<Integer> findBySubject(String subject,Integer pageNo);}

//填空題@Mapperpublic interface FillQuestionMapper { @Select('select * from fill_question where questionId in (select questionId from paper_manage where questionType = 2 and paperId = #{paperId})') List<FillQuestion> findByIdAndType(Integer paperId); @Select('select * from fill_question') IPage<FillQuestion> findAll(Page page); /** * 查詢最后一條questionId * @return FillQuestion */ @Select('select questionId from fill_question order by questionId desc limit 1') FillQuestion findOnlyQuestionId(); @Options(useGeneratedKeys = true,keyProperty ='questionId' ) @Insert('insert into fill_question(subject,question,answer,analysis,level,section) values ' + '(#{subject,},#{question},#{answer},#{analysis},#{level},#{section})') int add(FillQuestion fillQuestion); @Select('select questionId from fill_question where subject = #{subject} order by rand() desc limit #{pageNo}') List<Integer> findBySubject(String subject,Integer pageNo);}

//判斷題@Mapperpublic interface JudgeQuestionMapper { @Select('select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId})') List<JudgeQuestion> findByIdAndType(Integer paperId); @Select('select * from judge_question') IPage<JudgeQuestion> findAll(Page page); /** * 查詢最后一條記錄的questionId * @return JudgeQuestion */ @Select('select questionId from judge_question order by questionId desc limit 1') JudgeQuestion findOnlyQuestionId(); @Insert('insert into judge_question(subject,question,answer,analysis,level,section) values ' + '(#{subject},#{question},#{answer},#{analysis},#{level},#{section})') int add(JudgeQuestion judgeQuestion); @Select('select questionId from judge_question where subject=#{subject} order by rand() desc limit #{pageNo}') List<Integer> findBySubject(String subject,Integer pageNo);}

寫好mapper底層查詢后,需要創建service及其實現類來調用mapper底層。例如:

public interface JudgeQuestionService { List<JudgeQuestion> findByIdAndType(Integer paperId); IPage<JudgeQuestion> findAll(Page<JudgeQuestion> page); JudgeQuestion findOnlyQuestionId(); int add(JudgeQuestion judgeQuestion); List<Integer> findBySubject(String subject,Integer pageNo);}

@Servicepublic class JudgeQuestionServiceImpl implements JudgeQuestionService { @Autowired private JudgeQuestionMapper judgeQuestionMapper; @Override public List<JudgeQuestion> findByIdAndType(Integer paperId) {return judgeQuestionMapper.findByIdAndType(paperId); } @Override public IPage<JudgeQuestion> findAll(Page<JudgeQuestion> page) {return judgeQuestionMapper.findAll(page); } @Override public JudgeQuestion findOnlyQuestionId() {return judgeQuestionMapper.findOnlyQuestionId(); } @Override public int add(JudgeQuestion judgeQuestion) {return judgeQuestionMapper.add(judgeQuestion); } @Override public List<Integer> findBySubject(String subject, Integer pageNo) {return judgeQuestionMapper.findBySubject(subject,pageNo); }}

最后將輸出文件方法寫在controller層:

@RequestMapping('/exam/exportWord') public void exportWord(int examCode, HttpServletResponse response) throws FileNotFoundException{ //由于題目應于考試信息對應 所以需要先查出考試信息后根據pageId來查找對應的組卷信息ExamManage res = examManageService.findById(examCode);int paperId = res.getPaperId();List<MultiQuestion> multiQuestionRes = multiQuestionService.findByIdAndType(paperId); //選擇題題庫 1List<FillQuestion> fillQuestionsRes = fillQuestionService.findByIdAndType(paperId); //填空題題庫 2List<JudgeQuestion> judgeQuestionRes = judgeQuestionService.findByIdAndType(paperId);//響應到客戶端XWPFDocument document= new XWPFDocument();//分頁XWPFParagraph firstParagraph = document.createParagraph();//格式化段落firstParagraph.getStyleID();XWPFRun run = firstParagraph.createRun();int i = 1;run.setText('一、選擇題' + 'rn'); //換行for (MultiQuestion multiQuestion : multiQuestionRes) { String str = multiQuestion.getQuestion(); String str1 = multiQuestion.getAnswerA(); String str2 = multiQuestion.getAnswerB(); String str3 = multiQuestion.getAnswerC(); String str4 = multiQuestion.getAnswerD(); run.setText(i + '. ' + str + 'rn'); run.setText('A. ' + str1 + 'rn'); run.setText('B. ' + str2 + 'rn'); run.setText('C. ' + str3 + 'rn'); run.setText('D. ' + str4 + 'rn'); i++;}run.setText('二、填空題' + 'rn');for (FillQuestion fillQuestion : fillQuestionsRes) { String str = fillQuestion.getQuestion(); run.setText(i + '. ' + str + 'rn'); i++;}run.setText('三、判斷題' + 'rn');for (JudgeQuestion judgeQuestion : judgeQuestionRes) { String str = judgeQuestion.getQuestion(); run.setText(i + '. ' + str + 'rn'); i++;}document.createTOC();try { //設置相應頭 this.setResponseHeader(response, res.getSource() + '試卷.doc'); //輸出流 OutputStream os = response.getOutputStream(); document.write(os); os.flush(); os.close();} catch (Exception e) { e.printStackTrace();} } /** * 發送響應流方法 */ private void setResponseHeader(HttpServletResponse response, String fileName) {try { try {fileName = URLEncoder.encode(fileName, 'UTF-8'); } catch (UnsupportedEncodingException e) {e.printStackTrace(); } response.setContentType('application/octet-stream;charset=UTF-8'); response.setHeader('Content-Disposition', 'attachment;filename='+ fileName); //遵守緩存規定 response.addHeader('Pargam', 'no-cache'); response.addHeader('Cache-Control', 'no-cache');} catch (Exception ex) { ex.printStackTrace();} }

效果:

spring boot實現自動輸出word文檔功能的實例代碼

到此這篇關于spring boot實現自動輸出word文檔功能的文章就介紹到這了,更多相關spring boot自動輸出word文檔內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: word
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩在线观看一区二区三区| 亚洲女人av| 视频在线在亚洲| 欧美在线91| 欧美特黄视频| 日韩高清中文字幕一区二区| 国产精品免费精品自在线观看| 日韩在线卡一卡二| 99国产精品自拍| 狠狠久久婷婷| 一区在线视频观看| 欧美日韩一区二区综合| 国产传媒在线观看| 亚洲精品综合| 亚洲第一精品影视| 久久蜜桃精品| 日韩免费av| 激情久久久久久| 91精品精品| 中文字幕日本一区| 久久久久久黄| 久久亚洲视频| 免费在线亚洲欧美| 欧美资源在线| 日韩精品国产欧美| 国产精品极品在线观看| 91看片一区| 亚洲资源网站| 亚洲综合图色| 免费在线亚洲欧美| 制服诱惑一区二区| 久久精品国产999大香线蕉| 99成人超碰| 国产丝袜一区| 欧美网站在线| 国产一区二区三区免费在线| 视频福利一区| 亚洲一区二区日韩| 国产aa精品| 亚洲h色精品| 国产精品18| 香蕉人人精品| 国产欧美一区| 欧美日韩一区二区国产| 日本不卡在线视频| 久久亚洲国产精品一区二区| 精品日韩视频| 国产欧美二区| 亚洲青青久久| 午夜日本精品| 午夜久久中文| 精品三级久久久| 国产极品一区| 久久精品免费一区二区三区| 日韩精品电影| 热三久草你在线| 亚洲激情另类| 日本一区二区三区视频在线看| 午夜亚洲福利| 久久亚洲二区| 亚洲视频电影在线| 国产麻豆一区| 久久精品动漫| 麻豆精品在线| 亚洲第一精品影视| 视频一区日韩精品| 日韩在线高清| 日日夜夜免费精品| 久久久国产精品入口麻豆| 欧美午夜精品一区二区三区电影| 亚洲精品看片| 99视频精品全部免费在线视频| 91九色综合| 婷婷激情久久| 91精品国产自产精品男人的天堂| 伊人久久av| 国产日韩视频在线| 不卡一区综合视频| 久久精品国产99国产| 综合激情网站| 久久免费高清| 麻豆视频观看网址久久| 亚洲永久字幕| 国模大尺度视频一区二区| 日韩中文字幕麻豆| 亚洲深夜视频| 欧美另类中文字幕| 日韩欧美一区二区三区在线视频| 亚洲一二三区视频| 日韩欧美精品| 美日韩一区二区三区| 亚洲一区国产一区| 伊人久久av| 免费在线观看一区| 日本大胆欧美人术艺术动态| 成人免费电影网址| 国产精品成人3p一区二区三区| 久久久久久久久丰满| 国产精品分类| 视频一区免费在线观看| av高清不卡| 国产精品一站二站| 亚洲精品韩国| 国产精品视区| 97精品国产福利一区二区三区| 亚洲精品亚洲人成在线观看| 欧美日韩色图| 九九久久国产| 国产欧美二区| 久久国产婷婷国产香蕉| 日韩极品在线观看| 国产麻豆综合| 欧美精品一区二区久久| 色老板在线视频一区二区| 国产白浆在线免费观看| 精品国产午夜| 91亚洲精品在看在线观看高清| 男人操女人的视频在线观看欧美 | 日韩有吗在线观看| 亚洲一区二区三区免费在线观看 | 日韩午夜精品| 久久精品亚洲欧美日韩精品中文字幕| 国产精品videossex久久发布| 在线看片日韩| 亚洲免费影院| 中文无码久久精品| 亚洲黄色影院| 亚洲国产日韩欧美在线| 日韩高清中文字幕一区二区| 国产成人久久精品一区二区三区| 亚洲欧洲日韩| 模特精品在线| 免费成人性网站| 亚洲一区欧美二区| 日韩精品一二三| 亚洲资源在线| 日本免费一区二区视频| 日本中文字幕一区二区视频| 中文字幕亚洲影视| 国产伦理久久久久久妇女| 国产乱码精品一区二区亚洲| 亚洲精品系列| 国产乱人伦丫前精品视频| 国产精品1luya在线播放| 成人午夜在线| 久久久久久婷| 91av亚洲| 欧美日韩精品一本二本三本| 亚洲综合另类| 色综合视频一区二区三区日韩 | 视频一区中文字幕| 在线看片日韩| 亚洲资源网站| 国产伦精品一区二区三区视频 | 国产精品一卡| 福利一区二区三区视频在线观看| 欧美好骚综合网| 久久精品官网| 老司机精品久久| 91成人精品在线| 日韩av二区| 国精品一区二区三区| 日韩精品一二三区| 国产精品美女午夜爽爽| se01亚洲视频 | 久热精品在线| 香蕉久久一区| 精品久久精品| 久久精品一区二区不卡| 免费人成黄页网站在线一区二区| 色狠狠一区二区三区| 国产精品久久久网站| 国产一区2区在线观看| 美女网站一区| 蘑菇福利视频一区播放| 国产欧美精品| 欧美1级日本1级| 91精品国产自产观看在线| 中文在线а√天堂| 在线视频精品| 麻豆精品久久久| 亚洲天堂久久| 国产免费久久| 国产精品av一区二区| 久久精品超碰| 久久精品国产99久久| 日韩精品欧美大片| 日韩大片免费观看| 亚洲不卡视频| 中文字幕人成乱码在线观看| 香蕉成人久久| 国产中文欧美日韩在线| 亚洲综合日本| 日韩成人精品一区| 乱人伦精品视频在线观看| 欧美激情 亚洲a∨综合| 亚洲第一精品影视| 国产精品丝袜在线播放| 婷婷丁香综合| 久久中文字幕一区二区|