1

Im trying to call restapi and im getting error

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

properties

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

2
  • 1
    Do you have a file templates/view-fields.html on your classpath ? Commented Nov 3, 2021 at 18:23
  • Oh thanks. I had field named fields-view.html, i renamed to view-fields.html and started working. Thanks Commented Nov 3, 2021 at 18:28

1 Answer 1

1

According to your ss you have named the template as field-view.html but in controller you are returning view-fields.

Your code :

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"; } } 

Btw when you are making rest api you should use @RestController annotation instead of @Controller. Actually Controller will look for temples and RestController will return actual string or you can write html code too.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.