{"id":203590,"date":"2025-05-22T13:31:43","date_gmt":"2025-05-22T05:31:43","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203590\/"},"modified":"2025-05-22T13:31:43","modified_gmt":"2025-05-22T05:31:43","slug":"spring-boot-%e4%bd%bf%e7%94%a8-thymeleaf-%e6%97%b6%ef%bc%8c%e9%81%87%e5%88%b0error-resolving-template-%e9%94%99%e8%af%af%ef%bc%8c%e8%af%a5%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203590\/","title":{"rendered":"Spring Boot \u4f7f\u7528 Thymeleaf \u65f6\uff0c\u9047\u5230\u201cError resolving template []\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Spring Boot \u4f7f\u7528 Thymeleaf \u65f6\uff0c\u9047\u5230\u201cError resolving template []\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aSpring Boot \u4f7f\u7528 Thymeleaf \u65f6\uff0c\u9047\u5230\u201cError resolving template []\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/17314045736733231d4ae78.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u4f7f\u7528 spring boot \u65f6\u51fa\u73b0 thymeleaf \u627e\u4e0d\u5230\u6a21\u677f\u7684\u9519\u8bef<\/strong><\/p>\n<p>\u9047\u5230\u9519\u8bef\uff1a\u201cerror resolving template [], template might not exist or might not be accessible by any of the configured template resolvers\u201d\u65f6\uff0c\u53ef\u80fd\u662f\u7531\u4e8e thymeleaf \u627e\u4e0d\u5230\u6a21\u677f\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u786e\u8ba4\u6a21\u677f\u6587\u4ef6\u662f\u5426\u5b58\u5728\u4e14\u53ef\u8bbf\u95ee\uff1a<\/strong>\u786e\u4fdd\u6a21\u677f\u6587\u4ef6\u4f4d\u4e8e\u6b63\u786e\u7684\u76ee\u5f55\u4e2d\uff0c\u5e76\u4e14 thymeleaf \u53ef\u4ee5\u8bbf\u95ee\u8be5\u76ee\u5f55\u3002<\/li>\n<li>\n<p><strong>\u68c0\u67e5 thymeleaf \u914d\u7f6e\uff1a<\/strong>\u786e\u8ba4\u5df2\u6b63\u786e\u914d\u7f6e thymeleaf\uff0c\u5305\u62ec\u6a21\u677f\u89e3\u6790\u5668\u3002\u53ef\u4ee5\u68c0\u67e5 application.properties \u6216 application.yml \u6587\u4ef6\u4e2d\u662f\u5426\u6709\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>spring.thymeleaf.prefix=classpath:\/templates\/\nspring.thymeleaf.suffix=.html<\/pre>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0 thymeleaf \u4f9d\u8d56\uff1a<\/strong>\u5982\u679c\u4f60\u7684 spring boot \u9879\u76ee\u4e2d\u7f3a\u5c11 thymeleaf \u4f9d\u8d56\uff0c\u8bf7\u5c06\u5176\u6dfb\u52a0\u5230 pom.xml \u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/pre>\n<\/li>\n<li><strong>\u91cd\u542f\u5e94\u7528\u7a0b\u5e8f\uff1a<\/strong>\u5728\u8fdb\u884c\u4e0a\u8ff0\u66f4\u6539\u540e\uff0c\u9700\u8981\u91cd\u65b0\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u4ee5\u4fbf\u5e94\u7528\u66f4\u6539\u3002<\/li>\n<\/ol>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aSpring Boot \u4f7f\u7528 Thymeleaf \u65f6\uff0c\u9047\u5230\u201cError resolving template []\u201d\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot \u4f7f\u7528 T&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203590","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203590"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203590\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}