package it.com.action; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import it.com.bean.Knowledge; import it.com.bean.Questions; import it.com.bean.Subject; import it.com.bean.sub; import it.com.service.TeacherService; import it.com.service.UsersService; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sf.json.JSONArray; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class QuestionAction { @Resource TeacherService ts; public TeacherService getTs() { return ts; } public void setTs(TeacherService ts) { this.ts = ts; } @Resource UsersService us; public UsersService getUs() { return us; } public void setUs(UsersService us) { this.us = us; } @RequestMapping("tea.action") public ModelAndView selectSubject(HttpSession session){ List<Subject>list=ts.findSubject1(); session.setAttribute("listsubject", list); System.out.println("listsubject==="+list); return new ModelAndView("teacher/tecmain.jsp"); } @RequestMapping("tectable.action") //跳转到教师table页面 public ModelAndView tectable(HttpServletRequest request,HttpSession session) throws UnsupportedEncodingException{ String subjecttype=new String(request.getParameter("subjecttype").getBytes("ISO-8859-1"),"utf-8"); System.out.println("subjecttype==============="+subjecttype); List <Map>list=ts.findQuestion(subjecttype); session.setAttribute("listsub", list); session.setAttribute("subname", subjecttype); return new ModelAndView("teacher/table.jsp"); } @RequestMapping("findKnowledge.action") //查询知识点 public ModelAndView findKnowledge(String knowledge,int subjectid,HttpSession session){ List list=ts.findQuestionsByIdknow(knowledge,subjectid); session.setAttribute("listsub", list); return new ModelAndView("teacher/table.jsp"); } //根据questionid进行删除试题 @RequestMapping("deleteQuestionByid.action") public ModelAndView deleteQuestionByid(int questionid ,String subjecttype,HttpSession session){ ts.deleteQuestionById(questionid); List list=ts.findQuestion(subjecttype); session.setAttribute("listsub", list); return new ModelAndView("teacher/table.jsp"); } //增加试题 @RequestMapping("insertQuestion.action") public ModelAndView insertQuestion(String title, String ansA, String ansB, String ansC, String ansD, String trueans,int subjectid,String knowledge,String subjecttype,HttpSession session){ ts.insertQuestion(title, ansA, ansB, ansC, ansD,trueans,subjectid,knowledge); session.setAttribute("subjecttype", subjecttype); return new ModelAndView("teacher/up.jsp"); } //修改试题之前的查询 @RequestMapping("UpdatefindQuestionById.action") public ModelAndView UpdatefindQuestionById(int questionid,String subjecttype,HttpSession session){ System.out.println(questionid); List<Questions>list=ts.UpdatefindQuestionById(questionid); session.setAttribute("listques", list); session.setAttribute("subjecttype", subjecttype); return new ModelAndView("teacher/update.jsp"); } //修改试题通过questionid更新,subjectid直接获取后传递过去不能修改 @RequestMapping("UpdateQuestionById.action") public ModelAndView UpdateQuestionById(int questionid, String title, String ansA, String ansB, String ansC, String ansD, String trueans, int subjectid,String subjecttype, HttpSession session){ System.out.println(questionid+" "+title+" "+ansA+" "+ansB+" "+ansC+" "+ansD+" "+trueans+" "+subjectid+" "); int n=ts.UpdateQuestionById(questionid, title, ansA, ansB, ansC, ansD, trueans, subjectid); session.setAttribute("subjecttype", subjecttype); System.out.println(n); return new ModelAndView("teacher/up.jsp"); } //Excel批量导入试题 @RequestMapping("excel_insertQuestion.action") public ModelAndView ExcelInsertUser(HttpServletRequest request,HttpServletResponse response,HttpSession session) throws IOException{ /*String uri=request.getParameter("userUploadFile"); System.out.println("uri===="+uri);*/ String subjecttype=request.getParameter("subjecttype"); InputStream is=new FileInputStream("c:\\Question.xls"); POIFSFileSystem fs=new POIFSFileSystem(is); HSSFWorkbook wb=new HSSFWorkbook(fs); HSSFSheet hssfSheet=wb.getSheetAt(0); //获取第一个Sheet页 //遍历行Row Map map=new HashMap(); for(int rowNum=1;rowNum<=hssfSheet.getLastRowNum();rowNum++){ //得到每个具体的行 HSSFRow hssfRow=hssfSheet.getRow(rowNum); if(hssfRow==null){ continue; } //System.out.print("hssfRow=行=== "+hssfRow); //遍历列 for(int cellNum=0;cellNum<=hssfRow.getLastCellNum();cellNum++){ HSSFCell hssfCell=hssfRow.getCell(cellNum); if(hssfCell==null){ continue; } if(cellNum==0) { map.put("title", hssfCell); }else if(cellNum==1){ map.put("ansA", hssfCell); }else if(cellNum==2){ map.put("ansB", hssfCell); }else if(cellNum==3){ map.put("ansC", hssfCell); }else if(cellNum==4){ map.put("ansD", hssfCell); }else if(cellNum==5){ map.put("trueans", hssfCell); }else if(cellNum==6){ map.put("subjecttype", hssfCell); int subjectid=us.FindIdBysubType(map.get("subjecttype").toString()); map.put("subjectid", subjectid); }else if(cellNum==7){ map.put("knowledge", hssfCell); String title=map.get("title").toString(); String ansA=map.get("ansA").toString(); String ansB=map.get("ansB").toString(); String ansC=map.get("ansC").toString(); String ansD=map.get("ansD").toString(); String trueans=map.get("trueans").toString(); int subjectid=Integer.parseInt(map.get("subjectid").toString()); String knowledge=map.get("knowledge").toString(); System.out.println("-+++++++---"+title+" "+ansA+" "+ansB+" "+ansC+" "+ansD+" "+trueans+" "+subjectid+" "+knowledge); ts.insertQuestion(title, ansA, ansB, ansC, ansD,trueans,subjectid,knowledge); } //System.out.print("hssfCell=列= "+hssfCell); } System.out.println(); } session.setAttribute("subjecttype", subjecttype); return new ModelAndView("teacher/up.jsp"); } }

初嘤嘤嘤未来 LV7
2024年12月18日
ma406805131 LV19
2024年12月9日
2206371875 LV7
2024年3月14日
hongdongdong LV14
2023年12月3日
lbsers LV5
2023年5月6日
15152729192 LV3
2023年2月20日
唐唐丶 LV34
2023年2月19日
赵宇豪 LV1
2022年12月8日
1532593037 LV8
2022年11月30日
云翳tel青 LV11
2022年11月19日