本文主要是介绍Spingboot+thymeleaf返回頁面時報錯Error resolving template [home/login], template might not exist or might,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spingboot+thymeleaf返回頁面時報錯Error resolving template [home/login], template might not exist or might not be accessible by any of the configured Template Resolvers
controller代碼:
package com.sbweb.webtest.home.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
/*** @Author:glx* @Date:2021/6/18* @Content:*/
@Controller
@RequestMapping("/")
public class loginController {
@RequestMapping(value = "/login",method = RequestMethod.GET)public String _login(){System.out.println("login");return "home/login";}
}
報錯的具體信息:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jun 21 08:58:05 CST 2021
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [home/login], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [home/login], template might not exist or might not be accessible by any of the configured Template Resolversat org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607)at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:366)at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190)at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1396)at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1141)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1080)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)
原因及處理的辦法:
spring:profiles:active: @spring.profiles.active@mvc:static-path-pattern: /static/**view:suffix: .htmlprefix: /WEB-INF/views/thymeleaf:suffix: .htmlprefix: /WEB-INF/views/ ##修改為:classpath:/WEB-INF/views/encoding: UTF-8servlet:content-type: text/htmlcache: falsemode: LEGACYHTML5devtools:restart:enabled: true
這裡只是多了一個classpath,但是具體為什麼還沒有搞明白。
1.我需要返回的是頁面,所以不是講controller中的方法增加@ResponseBody
2.如果返回的路勁不對的話,controller會在return那裡出現波浪線,而我的controller沒有出現波浪線,所以應該也不是路徑的問題
这篇关于Spingboot+thymeleaf返回頁面時報錯Error resolving template [home/login], template might not exist or might的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!