我試圖呼叫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] 在 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] 在 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。render(ThymeleafView.java:190) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE] 在 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
也許這會有所幫助
uj5u.com熱心網友回復:
根據您的 ss,您已將模板命名為 asfield-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 代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/346833.html
