最近在实现一个身份证件多图片上传的功能,那么我们如何基于SSM框架来实现身份证件多图片上传的功能的?下面我们来实现一下。
Controller层:
@RequestMapping("identityAuthentication.do")
public void identityAuthentication(HttpServletRequest req, HttpServletResponse resp,Tbcustomer tbcustomer,
@RequestParam(value = "picture", required = true) MultipartFile[] myFile)
throws ServletException, IOException {
resp.setContentType("text/json");
try {
int CustomerID = Integer.parseInt(req.getSession()
.getAttribute("customerID").toString());
SimpleDateFormat SDF=new SimpleDateFormat("yyyy-MM-dd HH:mm::ss");//时间格式
String uploadPath = req.getServletContext().getRealPath("/")
+ "\\Temp";
int Record = 0;
List<String> imageName = new ArrayList<String>();
tbcustomer.setCustomerid(CustomerID);
//日志新增
Tblog tblog=new Tblog();
tblog.setCustomerid(CustomerID);
tblog.setOperationbehavior("个人中心(身份认证)");
try {
tblog.setOperationdate(SDF.parse(SDF.format(System.currentTimeMillis())));//日期
} catch (ParseException e1) {
e1.printStackTrace();
}
if (myFile.length >= 2) {
try {
if (myFile != null && myFile.length > 0) {
String uploadFileName = "";
for (MultipartFile multipartFile : myFile) {
uploadFileName = ReadFileUtil
.readWriteFile(multipartFile.getInputStream(),
multipartFile.getOriginalFilename(),
uploadPath);
imageName.add(uploadFileName);
}
if (imageName.size() >= 2) {
tbcustomer.setFrontofdocument(imageName.get(0));
tbcustomer.setBackofdocument(imageName.get(1));
}
}
} catch (Exception e) {
e.</