- 首页 > it经验 > >
前端代码:
Title
实体类:
package com.pojo;/** * 试题表 * */public class Topic {private Integer id;private String title;private String answerA;private String answerB;private String answerC;private String answerD;private int isMore;private String answer;private int sid;private int grade;public Topic() {}public Topic(String title, String answerA, String answerB, String answerC, String answerD, int isMore, String answer, int sid, int grade) {this.title = title;this.answerA = answerA;this.answerB = answerB;this.answerC = answerC;this.answerD = answerD;this.isMore = isMore;this.answer = answer;this.sid = sid;this.grade = grade;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getAnswerA() {return answerA;}public void setAnswerA(String answerA) {this.answerA = answerA;}public String getAnswerB() {return answerB;}public void setAnswerB(String answerB) {this.answerB = answerB;}public String getAnswerC() {return answerC;}public void setAnswerC(String answerC) {this.answerC = answerC;}public String getAnswerD() {return answerD;}public void setAnswerD(String answerD) {this.answerD = answerD;}public int getIsMore() {return isMore;}public void setIsMore(int isMore) {this.isMore = isMore;}public String getAnswer() {return answer;}public void setAnswer(String answer) {this.answer = answer;}public int getSid() {return sid;}public void setSid(int sid) {this.sid = sid;}public int getGrade() {return grade;}public void setGrade(int grade) {this.grade = grade;}}
【layui 上传excel,数据插入到数据库】mapper 接口
package com.mapper;import com.pojo.Topic;import org.apache.ibatis.annotations.Insert;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;import java.util.List;public interface TopicMapper {@Select("select * from topic")public ListgetAll();@Insert("")public boolean AddTopic(@Param("list") List list);}
service 接口
package com.service;import com.pojo.Topic;import org.apache.ibatis.annotations.Insert;import org.apache.ibatis.annotations.Select;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.util.List;public interface TopicService {public List getAll();public boolean AddTopic(List list);String UploadExcel(HttpServletRequest request, HttpServletResponse response);}
PowerServiceImpl 实现类
@Servicepublic class TopicServiceImpl implements TopicService {@Autowiredprivate TopicMapper mapper;@Overridepublic List getAll() {return mapper.getAll();}@Overridepublic boolean AddTopic(List list) {return mapper.AddTopic(list);}@Overridepublic String UploadExcel(HttpServletRequest request, HttpServletResponse response) {CommonsMultipartResolver cmr = new CommonsMultipartResolver(request.getServletContext());cmr.setDefaultEncoding("utf-8");cmr.setMaxInMemorySize(40960);cmr.setMaxUploadSize(10485760000L);MultipartFile file=null;if (cmr.isMultipart(request)) {MultipartHttpServletRequest multipartRequest = cmr.resolveMultipart(request);file = multipartRequest.getFile("file");// 与页面input的name相同}if(file.isEmpty()){try {throw new Exception("文件不存在!");} catch (Exception e) {e.printStackTrace();}}InputStream in =null;try {in = file.getInputStream();} catch (IOException e) {e.printStackTrace();}List> listob = null;try {listob = new ExcelUtils().getBankListByExcel(in,file.getOriginalFilename());} catch (Exception e) {e.printStackTrace();}Listlist=new ArrayList<>();for (int i = 0; i < listob.size(); i) {List
相关经验推荐