描述
日志信息:
org.thymeleaf.exceptions.TemplateInputException:
Error resolving template [/admin/types], template might not exist or might not be accessible by any of the configured Template Resolvers
使用windows本地运行没有问题,将项目部署到linux服务器上则会报错。
查看代码:
@Controller
@RequestMapping("/admin")
public class TypeController {
@GetMapping("/types")
public String types(@PageableDefault(size = 6, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable,
Model model){
model.addAttribute("page", typeService.listType(pageable));
return "/admin/types";
}
@GetMapping("/types/{id}/delete")
public String delete(@PathVariable Long id, RedirectAttributes attributes){
typeService.deleteTypeById(id);
attributes.addFlashAttribute("message", "删除成功");
return "redirect:/admin/types";
}
}
这里接口return “/admin/types”;代表的路径是http://myip:8081//admin/types,所对应的页面是templates//admin/目录下的types.html页面。在windows系统这个可以被解释为templates/admin目录,从而找到对应的页面文件,在linux系统下则会导致找不到页面文件。
解决方案
参考链接
将路径/admin/types改为admin/types——即去掉前面的“/”。
注意:代码里还有一种页面定位方式
return "redirect:/admin/types";
这里则是重定向,和前面的接口有所不同。这里可以理解为再去访问接口http://myip:8081/admin/types,而不能理解为http://myip:8081admin/types,否则就会出现404的错误。