@RequestMapping(value = "/imp",method = RequestMethod.POST,produces = "text/html;charset=UTF-8"
文件形式接收上传数据
HttpServletRequest request,HttpSession session) throws Exception {
Account account </span>= <span style="color: #0000ff;">this</span><span style="color: #000000;">.getStaticAccount();
</span><span style="color: #0000ff;">if</span> (myFile == <span style="color: #0000ff;">null</span> || myFile.getSize() == 0<span style="color: #000000;">) {
</span><span style="color: #0000ff;">return</span> "未选择任何<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a>,请选择<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a>后<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>!"<span style="color: #000000;">;
}
String fileType </span>=<span style="color: #000000;"> myFile.getOriginalFilename().substring(
myFile.getOriginalFilename().lastIndexOf(</span>"."<span style="color: #000000;">));
</span><span style="color: #0000ff;">if</span> (!fileType.equals(".xls") && !fileType.equals(".xlsx"<span style="color: #000000;">)) {
</span><span style="color: #0000ff;">return</span> "<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a>格式<a href="/tag/cuowu/" target="_blank" class="keywords">错误</a>,请<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>.xls或.xlsx格式<a href="/tag/wenjian/" target="_blank" class="keywords">文件</a>!"<span style="color: #000000;">;
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">String path = CommonsMethod.getProjectPath() ;</span>
String path=<span style="color: #000000;">request.getSession()
.getServletContext().getRealPath(</span>"/"<span style="color: #000000;">)
</span>+ "/importReserveExcel/"<span style="color: #000000;">;
String fileattr </span>=<span style="color: #000000;"> CommonsMethod.getNowCorrect2Millisecond()
</span>+<span style="color: #000000;"> myFile.getOriginalFilename().substring(
myFile.getOriginalFilename().lastIndexOf(</span>"."<span style="color: #000000;">));
final File targetFile </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> File(path,fileattr);
</span><span style="color: #0000ff;">if</span> (!<span style="color: #000000;">targetFile.exists()) {
targetFile.mkdirs();
}
</span><span style="color: #0000ff;">try</span><span style="color: #000000;"> {
myFile.transferTo(targetFile);
} </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (IllegalStateException e) {
e.printStackTrace();
} </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (IOException e) {
e.printStackTrace();
}
ArrayList</span><Object> dataList = <span style="color: #0000ff;">new</span> ArrayList<Object><span style="color: #000000;">();
</span><span style="color: #0000ff;">try</span><span style="color: #000000;"> {
dataList </span>=<span style="color: #000000;"> dayRecruitService.<span style="color: #339966;">readExcel</span>(
targetFile.getAbsolutePath(),</span>4<span style="color: #000000;">);
} </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (Exception e) {
</span><span style="color: #0000ff;">return</span><span style="color: #000000;"> e.getMessage();
}
</span><span style="color: #0000ff;">try</span><span style="color: #000000;"> {
String failImport </span>=<span style="color: #000000;"> dayRecruitService.importDayrecruit(
dataList,account);
} </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (RuntimeException e) {
</span><span style="color: #0000ff;">return</span><span style="color: #000000;"> e.getMessage();
} </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (Exception e) {
</span><span style="color: #0000ff;">return</span> "请仔细核对<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>格式(参考备注)"<span style="color: #000000;">;
}
</span><span style="color: #0000ff;">return</span> "<a href="/tag/shangchuan/" target="_blank" class="keywords">上传</a>成功"<span style="color: #000000;">;
}
private static final String[] headers = <span style="color: #0000ff;">new String[] {"日清日期","备注","面试人数","入职人数","招聘企业"};
public String importDayrecruit(List