import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.supcon.electronic.its.common.ViewExcel;
import com.supcon.electronic.its.common.ViewPDF;
/**
* 生成excel或PDF类型试图
* 根据参数进行数据组装,并跳转到相应的视图页面
* View Controller Bean<br>
*
* @author Tony Lin Created on 2008-10-22
* @version Version 1.0
*/
@Controller
@RequestMapping("/view.form")
public class ViewController extends BaseController {
@RequestMapping(params="method=exceltest",method=RequestMethod.GET)
public ModelAndView viewExcel(HttpServletRequest request, HttpServletResponse response){
log.debug("ViewController.viewExcel is started......");
List list = new ArrayList();
Map model = new HashMap();
list.add("test1");
list.add("test2");
model.put("list", list);
ViewExcel viewExcel = new ViewExcel();
log.debug("ViewController.viewExcel is ended......");
return new ModelAndView(viewExcel, model);
}
@RequestMapping(params="method=pdftest",method=RequestMethod.GET)
public ModelAndView viewPDF(HttpServletRequest request,
HttpServletResponse response) throws Exception {
List list = new ArrayList();
Map model = new HashMap();
list.add("test1");
list.add("test2");
model.put("list", list);
ViewPDF viewPDF = new ViewPDF();
return new ModelAndView(viewPDF, model);
}
}
4、用于Excel视图的视图子类
package com.lzk.common;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;
/**
* 生成excel视图,可用excel工具打开或者保存
* 由ViewController的return new ModelAndView(viewExcel, model)生成
* @author Tony Lin Created on 2008-10-22
* @version Version 1.0
*/
public class ViewExcel extends AbstractExcelView {