gpt4 book ai didi

java - Spring MVC AbstractXlsxView

转载 作者:行者123 更新时间:2023-11-30 03:06:32 35 4
gpt4 key购买 nike

我尝试使用 Spring 的 AbstractXlsxView,但它仅提示下载 application/octet-stream 文件类型而不是 excel 文件。

ExcelBuilder.java

public class ExcelBuilder extends AbstractXlsxView {

@Override
protected void buildExcelDocument(Map<String, Object> model,
Workbook workbook, HttpServletRequest request,
HttpServletResponse response) throws Exception {

Sheet latePaymentsSheet = workbook
.createSheet("Late Payments");
setLatePaymentHeader(latePaymentsSheet);

@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) model.get("map");
@SuppressWarnings("unchecked")
List<Map<String, Object>> latePaymentsList = (List<Map<String, Object>>) map
.get("latePayments");

setLatePaymentsRow(latePaymentsSheet, latePaymentsList);
}

Controller.java

@RequestMapping(value = "/export", method = RequestMethod.GET)
public ModelAndView exportToExcel() {

Map<String,Object> map = Dao.getData()

return new ModelAndView("ExcelBuilder", "map", map);
}

Excel-view.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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="ExcelBuilder" class="com.test.utility.ExcelBuilder">
</bean>
</beans>

最佳答案

您可以更改 @RequestMapping 并添加 products 属性。

@RequestMapping(value = "/export", method = RequestMethod.GET, produces="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

参见here对于其他 Mime 类型。

关于java - Spring MVC AbstractXlsxView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34630757/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com