我從springboot中的一個專案開始,我遇到了一個我以前從未見過的錯誤,我無法解決它,它是因為百里香依賴不起作用,我正在使用intellij idea社區版. 它不允許我使用 th:text,請看圖片。我已經洗掉了該專案并重新下載了幾次,洗掉了 m2 檔案夾,對我沒有任何作用。
這是我的控制器:
@Controller
public class IndexController {
@GetMapping(value = "/index")
public String index(Model model){
model.addAttribute("titulo", "nombre");
return "index";
}
}
這是 de index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>th:text="${titulo}"</title>
</head>
<body>
</body>
</html>
當我運行代碼 localhost 時沒有顯示正確的資訊,我已經安裝了依賴項。
在此處輸入影像描述
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在此處輸入影像描述
uj5u.com熱心網友回復:
您的模板被用作靜態資源。控制器有一個映射,/index但您已訪問http://localhost:8080. 將映射更改為@GetMapping("/")或訪問http://local host:8080/index. 您還應該檢查index.html專案中的位置。它應該在src/main/resources/templates.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/461385.html
上一篇:沒有為列舉springbootjava8的自定義注釋和驗證找到驗證器
下一篇:為什么在使用帶有@Grab的Groovy腳本時,帶有slf4j-nop的SLF4J會輸出StaticLoggerBinder警告
