java的poi技术下载Excel模板上传Excel读取Excel中内容

本文介绍了如何在Java的SSM框架下利用Apache POI库进行Excel操作,包括下载模板、上传文件及读取内容。通过`ClientController`控制器处理请求,`ReadExcel`工具类解析Excel数据,`WDWUtil`工具类验证文件格式。示例展示了处理文件上传、读取Excel数据并存储到`Customer`对象中。
摘要由CSDN通过智能技术生成

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();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值