Je ne pense pas qu'il y ait un moyen « Roo » spécifique de le faire, mais Spring MVC n'ont une classe AbstractExcelView qui utilise Apache POI et ne pose aucun problème - je pense qu'il est le meilleur vous pouvez espérer.
d'abord créer une classe de vue qui s'étend AbstractExcelView et met en œuvre la méthode 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\"");
}
}
ajouter ensuite les éléments suivants à votre webmvc-config.xml. Je ne pense pas que les questions de position, mais je l'ai sous la section où mon TilesConfigurer est répertorié:
<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>
Enfin créer des vues-excel.xml avec ce qui suit dans le:
<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>