English 中文(简体)
春卷Excel视图
原标题:spring roo excel view

I am trying to output an Excel file as the view in Spring Roo 1.0.2 What is the quickest way to do this? (Do I have to add new mapping etc?) At the moment I am using the default Roo AjaxUrlBasedViewResolver.

谢谢 (xiè xiè)

最佳回答

我不认为有一个特定的“Roo”做法来做这个,但是Spring MVC有一个使用Apache POI的AbstractExcelView类,不会造成任何问题-我认为这是你所能期望的最好的。

首先创建一个视图类,该类扩展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"");
    }
 }

然后将以下内容添加到您的webmvc-config.xml中。我认为位置无关紧要,但我将它放在我的TilesConfigurer列出的部分下面:

   <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>

最后,在意见中提出以下意见:

  <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>
问题回答

暂无回答




相关问题
multi-staged form using spring

please forgive me for this stupid questions. I just started developing web application using spring yesterday. The project that i worked on, have a multi staged form, that require users to complete ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

Spring Advice - submitting a form

I am having serious problems with code I have written with Spring so I have decided to start from scratch and ask for advice. Here are my requirements: When the page first loads I need a list of ...

How to implement Logout feature using Spring Web Mvc

I am new to Spring Web MVC.. Can I get some example or online link that shows me how to implement logout feature using spring web mvc ? I don t want to use the in built feature of spring security (i....

Exception thrown after processing onSubmitAction

I am very new to Spring and I have a simpleFormController with 2 methods. referenceData() with is called when the page loads and onSubmitAction() which is called on the submit of a form. I am ...

热门标签