gpt4 book ai didi

java - Apache POI - 基于 2 个日期参数导出到 Excel

转载 作者:行者123 更新时间:2023-12-02 09:15:11 25 4
gpt4 key购买 nike

在此版本之前,我有一个工作解决方案(java、spring boot、Apache POI),它从数据库导出所有数据并写入新的 Excel 文件。现在我想包含一个搜索参数,该参数将采用 URL 中包含的 2 个日期,与 requestReceivedDate 字段进行比较,并返回 2 个搜索参数之间的所有案例。我收到 404 not found,这表明 URL 不正确。我不确定 URL 存在什么问题。共享服务和存储库代码可帮助理解这些类如何交互。 http://localhost:8080/api/v1/piecases/download/28/09/2017/30/09/2019

Controller :

@GetMapping(value = "/piecases/download/{dateBefore}/{dateAfter}")
public String downloadExcel(Model model,
@RequestParam(name = "dateBefore") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateBefore,
@RequestParam(name = "dateAfter") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateAfter) {
model.addAttribute("cases", outboundBankErrorService.exportAllCasesByDate(dateBefore, dateAfter));
return "";
}

服务

public List<CaseData> exportAllCasesByDate(Date dateBefore, Date dateAfter) {
return bankErrorCaseDataRepository.findByRequestReceivedDateBetween(dateBefore, dateAfter);
}

存储库

 @Repository
public interface CaseDataRepository extends JpaRepository<CaseData, Long> {

@Query("SELECT cd FROM CaseData cd WHERE cd.requestReceivedDate BETWEEN :dateBefore AND :dateAfter")
List<CaseData> findByRequestReceivedDateBetween(@Param("dateBefore") Date dateBefore,
@Param("dateAfter") Date dateAfter);

}

最佳答案

http://localhost:8080/api/v1/piecases/download/28/09/2017/30/09/2019

将映射到: /piecases/download/{a}/{b}/{c}/{d}/{e}/{f} 这不是您想要的,因此404.一个简单的解决方法是使用查询字符串:

http://localhost:8080/api/v1/piecases/download?datebefore=28/09/2017&dateAfter=30/09/2019

@GetMapping(value = "/piecases/download")
public String downloadExcel(Model model,
@RequestParam(name = "dateBefore") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateBefore,
@RequestParam(name = "dateAfter") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateAfter) {
model.addAttribute("cases", outboundBankErrorService.exportAllCasesByDate(dateBefore, dateAfter));
return "";
}

关于java - Apache POI - 基于 2 个日期参数导出到 Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59050318/

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