application.properties:
#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.contentType=text/html
spring.thymeleaf.cache=false
视图返回:
/**
*
* @param registry
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/user/login").setViewName("canal/user/login");
registry.addViewController("/user/index").setViewName("canal/user/user_index");
}
结构目录:
报警告:
2018-08-06 15:46:12.829 INFO 4416 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/user/login] onto handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2018-08-06 15:46:12.829 INFO 4416 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/user/index] onto handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2018-08-06 15:46:12.838 INFO 4416 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 15:46:12.839 INFO 4416 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 15:46:12.839 INFO 4416 --- [ main] o.s.w.s.h.SimpleUrlHandlerMapping : Mapped URL path [/static/canal/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 15:46:12.893 WARN 4416 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2018-08-06 15:46:13.167 INFO 4416 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-08-06 15:46:13.169 INFO 4416 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'druidDataSource' has been autodetected for JMX exposure
2018-08-06 15:46:13.178 INFO 4416 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'druidDataSource': registering with JMX server as MBean [com.alibaba.druid.pool:name=druidDataSource,type=DruidDataSource]
2018-08-06 15:46:13.231 INFO 4416 --- [ main] o.s.b.w.e.t.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/CANAL'
2018-08-06 15:46:13.237 INFO 4416 --- [ main] c.Application : Started Application in 3.552 seconds (JVM running for 4.212)
访问: localhost:8080/CANAL/user/login
出现:
2018-08-06 16:03:36.778 ERROR 4416 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/CANAL] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "canal/user/login", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "canal/user/login", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:870) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:354) ~[thymeleaf-spring5-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:187) ~[thymeleaf-spring5-3.0.9.RELEASE.jar:3.0.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069) ~[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]