试卷导入

来源:互联网 发布:站桩怎么学 知乎 编辑:程序博客网 时间:2024/04/28 19:06

试卷导入,word导入,这个需要用标签的形式来进行规定:

比如<试卷><名称>物理试卷</名称></试卷>

这样进行规定。

@Autowiredprivate QuestionDao questionDao;@Autowired    private MessageSource messageSource;/** * 读取word * @param path * @return */@Overridepublic String wordRead(String path){File file = new File(path);        try {            FileInputStream fis = new FileInputStream(file);            WordExtractor wordExtractor = new WordExtractor(fis);            String text = wordExtractor.getText();               return text;        } catch (IOException e) {            e.printStackTrace();        }return "";}/** * 获取标签中的内容 * @param text * @param tag * @return */@Overridepublic String getTagContent(String text,String tag){String bt = "";int btIndex = text.indexOf("<"+tag+">");int btLastIndex = text.indexOf("</"+tag+">");    if(btIndex!=-1&&btLastIndex!=-1){    bt = text.substring(btIndex+("<"+tag+">").length(), btLastIndex);    }return bt;}/** * 获取某一组的某一个单项,如单选题这个组别中有多个单选题(单项) * @param text * @param tag1 单项标签名,(例如:题) * @param tag2 上面标签的名称或者其他什么(标签) * @return */@Overridepublic void getSingleContent(String text,String tag1,String tag2,String questionType,Resource testPaper){for(int i = 1;i>=1;i++){    String tContent = getTagContent(text,tag1+i);    String tMc = getTagContent(tContent,tag2);    if(Strings.isNullOrEmpty(tContent)||Strings.isNullOrEmpty(tMc)) break;    if(i18n(XZT).equals(questionType)){    for(int j = 1;j>=1;j++){        String xxContent = getTagContent(tContent,i18n(XX));        String cContent = getTagContent(xxContent,i18n(CONTENT));        if(Strings.isNullOrEmpty(xxContent)||Strings.isNullOrEmpty(cContent)) break;        System.out.println(cContent);        }    }    //下面再做添加操作    System.out.println(tMc);        Resource question = new Resource();    ResourceType resourceType = resourceTypeDao.findByCode(TypeCode.QUESTION);    question.setDescription(tMc);    question.setType(resourceType);    questionDao.save(question);        String daMc = getTagContent(tContent,i18n(QuestionService.DA));        this.saveExValue(question, "rightAnswer", daMc);    this.saveExValue(question, "questionType", questionType);        List<Resource> questions = testPaper.getItems();    if(questions==null){    questions = Lists.newArrayList();    questions.add(question);    testPaper.setItems(questions);    }else{    testPaper.getItems().add(question);    }    resourceDao.update(testPaper);        }}/** * 设置资源中某个字段的value * @param resource 资源 * @param fieldName 字段名称 * @param value 值 */protected void saveExValue(Resource resource, String fieldName, String value){ExField rAField = exFieldDao.findByNameAndType(fieldName, resource.getType().getId());ExValue rAValue = new ExValue();rAValue.setField(rAField);rAValue.setResource(resource);rAValue.setValue(value);exValueDao.save(rAValue);}@Overridepublic List<Resource> listQuestionByTypeAndPaper(String questionType, long paperId) {return questionDao.listQuestionByTypeAndPaper(questionType, paperId);}protected String i18n(String message) {        return messageSource.getMessage(message, null, null);    }@Overridepublic void importQuestions(String text) {//--------------------------------标题------------------------------------    String btContent = this.getTagContent(text,i18n(QuestionService.BT));    String btMc = this.getTagContent(btContent,i18n(QuestionService.MC));    System.out.println(btMc);            Resource testPaper = new Resource();    testPaper.setName(btMc);    ResourceType testPaperType = resourceTypeDao.findByCode(TypeCode.TEST_PAPER);    testPaper.setType(testPaperType);    questionDao.save(testPaper);        //----------------------------------选择题---------------------------------------    String xztContent = this.getTagContent(text,i18n(QuestionService.XZT));    String xztMc = this.getTagContent(xztContent,i18n(QuestionService.MC));        System.out.println(xztMc);    this.getSingleContent(xztContent,i18n(QuestionService.T),i18n(QuestionService.MC),i18n(QuestionService.XZT),testPaper);        //----------------------------------判断题---------------------------------------    String pdtContent = this.getTagContent(text,i18n(QuestionService.PDT));    String pdtMc = this.getTagContent(pdtContent,i18n(QuestionService.MC));    System.out.println(pdtMc);    this.getSingleContent(pdtContent,i18n(QuestionService.T),i18n(QuestionService.MC),i18n(QuestionService.PDT),testPaper);        //----------------------------------填空题---------------------------------------    String tktContent = this.getTagContent(text,i18n(QuestionService.TKT));    String tktMc = this.getTagContent(tktContent,i18n(QuestionService.MC));    System.out.println(tktMc);    this.getSingleContent(tktContent,i18n(QuestionService.T),i18n(QuestionService.MC),i18n(QuestionService.TKT),testPaper);        //----------------------------------解答题---------------------------------------    String jdtContent = this.getTagContent(text,i18n(QuestionService.WDT));    String jdtMc = this.getTagContent(jdtContent,i18n(QuestionService.MC));    System.out.println(jdtMc);    this.getSingleContent(jdtContent,i18n(QuestionService.T),i18n(QuestionService.MC),i18n(QuestionService.WDT),testPaper);}

message.properties:

biaoti = \u6807\u9898xuanzeti = \u9009\u62E9\u9898panduanti = \u5224\u65AD\u9898tiankongti = \u586B\u7A7A\u9898wendati = \u95EE\u7B54\u9898ti = \u9898mingcheng = \u540D\u79F0xuanxiang = \u9009\u9879neirong = \u5185\u5BB9xuanxiang = \u9009\u9879neirong = \u5185\u5BB9daan = \u7B54\u6848

试卷,word:

<标题><名称>物理试卷</名称></标题><选择题><名称>一.选择题(60分)</名称><题1><名称>1.一场大雪过后,人们会感到外面万籁俱静.究其原因,你认为正确的是( )</名称><选项1><内容>A.可能是大雪后,行驶的车辆减少,噪声减小 </内容></选项1><选项2><内容>B.可能是大雪蓬松且多孔,对噪声有吸收作用</内容></选项2><选项3><内容>C.可能是大雪后,大地银装素裹,噪声被反射 </内容></选项3><选项4><内容>D.可能是大雪后气温较低,噪声传播速度变慢 </内容></选项4></题1><题2><名称>2.助听器的工作原理是利用仪器( )</名称><选项1><内容>A.引起头骨、颌骨振动,传到听觉神经,引起听觉 </内容></选项1><选项2><内容>B.引起鼓膜振动,经过听小骨及其他组织传给听觉神经,引起听觉</内容></选项2><选项3><内容>C.产生超声波直接作用在听觉神经引起听觉</内容></选项3><选项4><内容>D.产生声波直接作用在听觉神经引起听觉</内容></选项4></题2><题3><名称>3.如图1所示,老师用同样的力吹一根吸管,并将它的长度逐渐剪短,他在研究声音的( )</名称><选项1><内容>A.响度与吸管长短的关系</内容></选项1><选项2><内容>B.音调与吸管材料的关系</内容></选项2><选项3><内容>C.音调与吸管长短的关系</内容></选项3><选项4><内容>D.音色与吸管材料的关系</内容></选项4></题3></选择题><判断题><名称>二.判断题(10分)</名称><题1><名称>1.一物体受外力越大,加速度越大( )</名称></题1><题2><名称>2.物体所受的合外力越大,速度越大( )</名称></题2><题3><名称>3.物体的加速度大小不变一定守恒力作用( )</名称></题3><题4><名称>4.如果不考虑空气阻力的作用,不同轻重,不同形状当物体下落的快慢是相同的(  )</名称></题4><题5><名称>5水平公路上行驶的汽车。当发动机熄火后,行驶速度越来越小,在这个过程中,汽车的机械能守恒(  )</名称></题5></判断题><填空题><名称>三.填空题(10分)</名称><题1><名称>1、声音在15℃空气中的传播速度是_______m/s;</名称></题1><题2><名称>2、超声波的频率高于_________Hz,次声波的频率低于______Hz。</名称></题2><题3><名称>3、光(电磁波)在真空中的传播速度是c= _______ m/s=_________km/s。</名称></题3><题4><名称>4、正常人的眼睛的远点在_________,近点在大约_________ 处,明视距离大约是_________处</名称></题4></填空题><问答题><名称>四.问答题(60分)</名称><题1><名称>1.夏天游泳时,一上岸就感到凉快;当有风吹来时,更觉得冷。为什么?(96五)5分。</名称></题1><题2><名称>2.试分析蒸发和沸腾的相同处和不同点。(98.五 0.43)5分。</名称></题2><题3><名称>3.小明暑假在家休息时觉得十分炎热,请你用学过的物理知识想出二种消暑降温的好办法,并简要说明理由。</名称></题3><题4><名称>4.医生为病人检查牙齿时,常拿一个带把的金属小平面镜在酒精灯的火焰上烤一烤,然后再放入病人的口腔中,这样做的主要目的是什么?(4分)</名称></题4></问答题>


0 0
原创粉丝点击