模板可能不存在
Template might not exists
我正在尝试调用 rest api 但出现错误
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: Error resolving template [view-fields], template might not exist or might not be accessible by any of the configured Template Resolvers
at 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]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at 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]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1400) ~
etc
属性
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
Maybe this would help
根据 your ss 您已将模板命名为 field-view.html
但在控制器中您 returning 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 会 return 实际字符串或者你也可以写 html 代码。
我正在尝试调用 rest api 但出现错误
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: Error resolving template [view-fields], template might not exist or might not be accessible by any of the configured Template Resolvers at 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] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE] at 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] at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1400) ~ etc
属性
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
Maybe this would help
根据 your ss 您已将模板命名为 field-view.html
但在控制器中您 returning 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 会 return 实际字符串或者你也可以写 html 代码。