異常: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");

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM