ApacheCrazyFan 2018-08-06 00:04 采纳率: 100%
浏览 8710
已结题

springboot配置thymeleaf

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]


展开全部

  • 写回答

5条回答 默认 最新

  • ApacheCrazyFan 2018-08-06 00:07
    关注

    thymeleaf:
    图片说明

    评论
  • Lei_Da_Gou 2018-08-06 01:37
    关注

    spring boot 的一个重点是简化配置,诶之thymeleaf只需要配置application.properties和pom.xml中引入依赖就行了。不用你写任何配置类。

    评论
  • dabocaiqq 2018-08-06 06:37
    关注
    评论
  • 瓦史托德 2018-08-06 18:22
    关注

    你应该访问 localhost:8080/user/login

    评论
  • qq_25261763 2018-08-06 23:55
    关注

    图片说明
    页面放在resources/templates包下

    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 GUIDE to App Designer Migration Tool for MATLAB
  • ¥50 第三代非支配排序遗传算法(NSGA-Ⅲ)和多目标粒子群优化算法(MOPSO)的实现
  • ¥15 hbuilderx写一个这个网页🙏
  • ¥20 plant simulation与python com接口实时数据交互
  • ¥15 有关汽车的MC9S12XS128单片机实验
  • ¥15 求c语言动态链表相关课程有偿,或能将这块知识点讲明白
  • ¥15 FLKT界面刷新异常
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥50 单细胞测序拟时序分析
  • ¥50 运行springboot项目报错
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部