java的poi技术下载Excel模板上传Excel读取Excel中内容(SSM框架)
使用到的jar包
JSP: client.jsp
按 Ctrl+C 复制代码
按 Ctrl+C 复制代码
controller: ClientController.java
package com.shiliu.game.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.shiliu.game.domain.bean.Customer;
import com.shiliu.game.utils.ReadExcel;
import com.shiliu.game.utils.WDWUtil;
/**
-
@author wkr
-
@Date 2016-11-18
*/
@Controller
@RequestMapping("/client")
public class ClientController {private static Log log = LogFactory.getLog(ClientController.class);
/**-
访问controller进入操作页面
-
@return
/
@RequestMapping(value="/init")
public String init(){
System.out.println(“控制台输出:初始化页面信息”);
return “client/client”;
}
/* -
上传Excel,读取Excel中内容
-
@param file
-
@param request
-
@param response
-
@return
-
@throws IOException
*/
@RequestMapping(value = “/batchimport”,method = RequestMethod.POST)
public String batchimport(@RequestParam(value=“filename”) MultipartFile file,
HttpServletRequest request,HttpServletResponse response) throws IOException{
log.info(“ClientController …batchimport() start”);
String Msg =null;
boolean b = false;//判断文件是否为空
if(file==null){
Msg =“文件是为空!”;
request.getSession().setAttribute(“msg”,Msg);
return “client/client”;
}//获取文件名
String name=file.getOriginalFilename();
-