我已经使用spring boot和itextpdf 5编写了一个代码,实际上我正在尝试执行类似此示例的操作
https://github.com/aboullaite/SpringBoot-Excel-Csv
当我在STS IDE中运行它时,我的代码工作正常,但是当我创建jar文件并运行它时,它显示为错误解决模板错误,有人可以帮忙吗
编辑:-我正在使用百里香进行html查看
这是我的webconfig类
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer
.defaultContentType(MediaType.APPLICATION_JSON)
.favorPathExtension(true).ignoreAcceptHeader(true);
}
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);
// Define all possible view resolvers
List<ViewResolver> resolvers = new ArrayList<>();
resolvers.add(csvViewResolver());
resolvers.add(excelViewResolver());
resolvers.add(pdfViewResolver());
resolver.setViewResolvers(resolvers);
return resolver;
}
/*
* Configure View resolver to provide XLS output using Apache POI library to
* generate XLS output for an object content
*/
@Bean
public ViewResolver excelViewResolver() {
return new ExcelViewResolver();
}
/*
* Configure View resolver to provide Csv output using Super Csv library to
* generate Csv output for an object content
*/
@Bean
public ViewResolver csvViewResolver() {
return new CsvViewResolver();
}
/*
* Configure View resolver to provide Pdf output using iText library to
* generate pdf output for an object content
*/
@Bean
public ViewResolver pdfViewResolver() {
return new PdfViewResolver();
}
}
这是我的控制器方法
@GetMapping( "/download")
public String download(Model model) {
model.addAttribute("cards", new StudentsDto());
return "getReportCard";
}
@PostMapping("/download")
public String postReportCard(@ModelAttribute("cards") StudentsDto cards, Model model){
List<Students> sList=studentService.searchByClassSectionBySession(cards.getClassSection(), cards.getSession());
model.addAttribute("studentsList", sList);
return "";
}
我的问题是,如果通过我的STS IDE将代码作为spring boot应用程序运行时,thingthinbg运行良好,那么为什么我创建的jar不显示pdf视图? 我从sts ide创建了jar,我做了maven清理,然后使用maven install创建了jar。
这是一个愚蠢的错误,我不知道该怎么做,但是在我的模板文件夹中,我将文件getReportCard.html的名称更改为getReportCArd.html。
这是一个愚蠢的错误,我检查了每种可能的配置。 :-)