Error resolving template [excel/readExcel], template might not exist or might not be accessible by
原创
©著作权归作者所有:来自51CTO博客作者刘大猫26的原创作品,请联系作者获取转载授权,否则将追究法律责任
文章目录
- 错误场景
- 代码如下
- 解决方案2种
- 第一种方案:@Controller => @RestController
- 第二种方案:方法添加注解 @ResponseBody
错误场景
在使用阿里巴巴的easyexcel,调用后台接口读取指定excel文件进行输出打印时报错
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [excel/readExcel], template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.14.RELEASE.jar:3.0.14.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.14.RELEASE.jar:3.0.14.RELEASE]
代码如下
pom.xml
<!--读取excel文件-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
Controller
//读取指定的Excel
@RequestMapping(value = "/readExcel")
public List<Teacher> readExcel() {
String fileName = "C:\\Users\\211145187\\Desktop\\fsdownload\\details (1).xls";
TeacherListener studentListener = new TeacherListener();
EasyExcel.read(fileName, Teacher.class, studentListener).sheet().doRead();
return studentListener.getTeacherList();
}
读取的excel文件如下
解决方案2种
第一种方案:@Controller => @RestController
第二种方案:方法添加注解 @ResponseBody