欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring Boot集成FreeMarker 時訪問不到.ftl文件的配置步驟

 更新時間:2025年04月23日 10:47:24   作者:旅行的獅子  
Spring Boot 要集成 FreeMarker 模板引擎時必須經(jīng)過正確的配置,大致可分為5 個步驟,下面分步驟給大家介紹的非常詳細,感興趣的朋友一起看看吧

Spring Boot 項目集成 FreeMarker時,未進行正確配置的話會出現(xiàn)404錯誤,如圖所示:

Spring Boot 要集成 FreeMarker 模板引擎時必須經(jīng)過正確的配置,大致可分為5 個步驟:

引入依賴

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
 </dependency>

在application.yml文件中進行如下配置,務(wù)必配置正確(.properties文件也一樣)

  freemarker:
    template-loader-path: classpath:/templates  # classpath:  一定不能漏寫
    cache: false
    charset: UTF-8
    check-template-location: true
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    request-context-attribute: req
    suffix: .ftl

曾經(jīng)因為漏寫 classpath: ,花了1個小時找不到原因

編寫controller類

@Controller
@RequestMapping("/")
public class OrderController {
    @GetMapping("/list")
    public ModelAndView list(Map<String, Object> map) {
        map.put("name", "chenf24k");
        return new ModelAndView("name", map);
    }
}

在Spring Boot項目的resources/templates下新建 name.ftl模板文件

<h1>FreeMarker</h1>
<h2>${name}</h2>

啟動Spring Boot 項目后瀏覽器輸入地址: http://127.0.0.1:8080/list 進行訪問。

到此這篇關(guān)于Spring Boot集成FreeMarker 時訪問不到.ftl文件的配置步驟的文章就介紹到這了,更多相關(guān)Spring Boot訪問不到.ftl文件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論