异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法

在开发环境下正常,但使用jar运行时,报错Error resolving template template might not exist or might not be accessible,意思是模板页不在,但在jar里存在该模板页

1.查看pom.xml文件是否添加

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

 2.在application.yml添加相应的thymeleaf 的配置文件

    thymeleaf:
      prefix: classpath:/templates/  #prefix:指定模板所在的目录
      check-template-location: true  #check-tempate-location: 检查模板路径是否存在
      cache: false  #cache: 是否缓存,开发模式下设置为false,避免改了模板还要重启服务器,线上设置为true,可以提高性能。
      suffix:  .html
      #encoding: UTF-8
      #content-type: text/html
      mode: HTML5

  3.看你的页面路径地址

4.①的访问路径  直接 localhost:8080 + 你页面地址

  ②的访问路径  在controller   

@Controller
@RequestMapping("demo")
public class LoginCtrl {
	
	 @RequestMapping("/demo3")
	public ModelAndView login(){
		ModelAndView mv =  new ModelAndView("temp");
		return mv;
	}

}

  

  ③ 的访问路径跟②一致,不过 

	ModelAndView mv =  new ModelAndView("/back/bcak");

  

原文地址:https://www.cnblogs.com/wudixiaoguaishou/p/9993747.html