java - 模板可能不存在
问题描述
我试图调用restapi并且我得到错误
package czajka.piotr.restapi.viewcontroller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class FieldViewController {
@RequestMapping("/view-fields")
public String viewFields()
{
return "view-fields";
}
}
org.thymeleaf.exceptions.TemplateInputException:解析模板时出错 [view-fields],模板可能不存在或可能无法被 org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) 上的任何已配置模板解析器访问~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12 .RELEASE] 在 org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072 ) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:366) ~[thymeleaf-spring5-3.0.12.RELEASE。 jar:3.0.12.RELEASE] 在 org.thymeleaf.spring5.view.ThymeleafView。渲染(ThymeleafView.java:190)~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1400)~等
特性
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/serverdb?useUnicode=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=12345678
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
server.port=8081
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
解决方案
根据您的 ss您已将模板命名为field-view.html
但在控制器中您正在返回view-fields
。
你的代码:
package czajka.piotr.restapi.viewcontroller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class FieldViewController {
@RequestMapping("/view-fields")
public String viewFields()
{
return "field-view";
}
}
顺便说一句,当你制作rest api时,你应该使用@RestController注释而不是 @Controller。实际上, Controller会寻找寺庙,RestController会返回实际的字符串,或者你也可以编写 html 代码。
推荐阅读
- c++ - c ++ usleep在linux上立即返回
- javascript - 如何设置 for 循环中的索引但又未定义?
- php - 在 nginx 上安装 Multi php 版本
- linux - Linux 服务器密码已过期。修改密码时不重播
- google-chrome-extension - Chrome扩展如何在扩展目录中写入文件
- git - 使用 puppet 使 git 命令行变得丰富多彩
- java - 如何避免Java中的无限循环
- vb.net - 输入正确的用户名和密码后登录无效
- python - 尝试为管理员安装皮肤时出现 Django 路径错误
- c# - 如何使用数据网格视图(Winforms、C#)更新 MySQL 表?