3
我想输出一个Excel文件作为Spring Roo 1.0.2中的视图 这样做的最快方法是什么? (我必须添加新的映射等?)目前我使用默认的Roo AjaxUrlBasedViewResolver。spring roo excel view
感谢
我想输出一个Excel文件作为Spring Roo 1.0.2中的视图 这样做的最快方法是什么? (我必须添加新的映射等?)目前我使用默认的Roo AjaxUrlBasedViewResolver。spring roo excel view
感谢
我不认为有这样做的具体的“袋鼠”的方式,但是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>
最后创建视图,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>