Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc SpringRooExcel视图_Spring Mvc_Spring Roo - Fatal编程技术网

Spring mvc SpringRooExcel视图

Spring mvc SpringRooExcel视图,spring-mvc,spring-roo,Spring Mvc,Spring Roo,我试图在SpringRoo1.0.2中输出一个Excel文件作为视图 最快的方法是什么? (是否必须添加新映射等?) 谢谢我不认为有一种特定的“Roo”方式可以做到这一点,但是Spring MVC确实有一个AbstractExcelView类,它使用Apache POI并且不会引起任何问题-我认为这是您所能期望的最好的方式 首先创建一个视图类,该类扩展AbstractExcelView并实现buildExcelDocument方法: import org.springframework.web

我试图在SpringRoo1.0.2中输出一个Excel文件作为视图 最快的方法是什么? (是否必须添加新映射等?)


谢谢

我不认为有一种特定的“Roo”方式可以做到这一点,但是Spring MVC确实有一个AbstractExcelView类,它使用Apache POI并且不会引起任何问题-我认为这是您所能期望的最好的方式

首先创建一个视图类,该类扩展AbstractExcelView并实现buildExcelDocument方法:

 import org.springframework.web.servlet.view.document.AbstractExcelView;

 public class XlsView  extends AbstractExcelView { 

   @Override
   protected void buildExcelDocument(
            Map<String, Object> model, HSSFWorkbook workbook, 
            HttpServletRequest request, HttpServletResponse response) throws Exception {
      //Apache POI code to set up the HSSFWorkbook goes here
      response.setHeader("Content-Disposition", "attachment; filename=\"file.xls\"");
    }
 }
import org.springframework.web.servlet.view.document.AbstractExcelView;
公共类XlsView扩展了AbstractExcelView{
@凌驾
受保护的无效文件(
地图模型、HSSF工作手册、,
HttpServletRequest请求、HttpServletResponse响应)引发异常{
//用于设置HSSF工作簿的Apache POI代码如下
setHeader(“内容处置”、“附件;文件名=\”file.xls\”);
}
}
然后将以下内容添加到webmvc-config.xml中。我认为这个职位并不重要,但我的TileConfigure列表下面有一节:

   <bean id="excelViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
            <property name="order" value="1"/>
            <property name="location" value="/WEB-INF/views/views-excel.xml"/>
        </bean>

最后创建views-excel.xml,其中包含以下内容:

  <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
     <bean name="XlsView" class="com.your.package.XlsView"/>
  </beans>