【发布时间】:2019-07-22 13:35:22
【问题描述】:
我尝试从 Ajax 请求中调用 Spring Boot 控制器:
$('#female').click(function(){
$('#analysisTable').DataTable( {
"ajax": '/analyse/female'
});
});
这背后的想法是将列表加载到 js 数据表中。 控制器看起来像:
@GetMapping("/analyse/female")
public List<GenderAnalysis> analysisByFemale(final Model model) {
final List<GenderAnalysis> result = analyseDao.getAnalysisByGender(AnalyseDAO.Gender.Female);
return result;
}
控制器工作正常。但我得到一个 Thymeleaf 模板错误。 每个响应都将通过 ThymeleafLayoutInterceptor 处理,并将“正常”(不是 ajax)请求加载到模板中。
错误如下:
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/analyse/female.html]")
我知道没有 female.html 资源,我什至没有。只需将原始列表提供给 ajax 调用。
即使使用模板,我也不确定如何使用 Spring Boot+Thymeleaf+Ajax。 会不会是拦截器的处理问题?我能做些什么?有人能帮忙吗?
【问题讨论】:
标签: ajax spring-boot thymeleaf