直接上代码~
@Configuration
public class ExportAlarmController {
@Bean(name = "csvView")
public CSVView cSVView() {
return new CSVView();
}
@Autowired
ExportAlarmService exportAlarmService;
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/exportAlarm", method = RequestMethod.POST)
public ModelAndView exportAlarm(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("-----------------exportAlarm------------------");
Map requestValue = request.getParameterMap();
List list = exportAlarmService.exportAlarm(requestValue);
Map result = new HashMap();
result.put("list", list);
result.put("name", "Alarm");
return new ModelAndView("csvView", result);
}
}
执行上面的代码后出现错误~
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "csvView", template might not exist or might not be accessible by any of the configured Template Resolvers
请问这个要怎么解决呢?
new ModelAndView("csvView", result) 这个所指向的页面似乎不存在……
先检查配置:
#spring.thymeleaf.check-template-location=true
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.excluded-view-names= # comma-separated list of view names that should be excluded from resolution
#spring.thymeleaf.view-names= # comma-separated list of view names that can be resolved
#spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html # ;charset= is added
#spring.thymeleaf.cache=true # set to false for hot refresh
然后看spring.thymeleaf.prefix配置对应的路径下是否有csvView.html文件