亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Spring Boot如何整合FreeMarker模板引擎

瀏覽:31日期:2023-08-09 18:19:32

POM

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

項目結構

src/ +- main/ +- java/ | +- com | +- controller/ | | +- IndexController.class | +- Application.class +- resources/ +- templates/ +- index.ftlh Application為應用程序啟動類 IndexController為控制器,里面含有一個index請求處理方法,它返回index字符串,表示渲染模板文件index.ftlh。 index.ftlh為freemarker模板文件

Applciation.class

@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}

IndexController.class

@Controllerpublic class IndexController { @GetMapping('/index') public String index(Model model) { model.addAttribute('name', 'Alice'); return 'index'; }}

注意@ResponseBody注解不能和freemarker一起使用,所以此處不能標注@RestController注解。

index.ftlh

<!DOCTYPE html><html><head> <title>test</title></head><body>hello ${name}!</body></html>

運行

運行Application類里的main方法。

然后訪問localhost:8080/index,結果展示為:

hello Alice!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 黄色一级视频免费 | 中美日韩在线网免费毛片视频 | 欧美日比视频 | 国产精品福利自产拍网站 | 国产aaa免费视频国产 | 俄罗斯一级成人毛片 | 免费日比视频 | 一级片网 | 免费一级在线观看 | 成人精品视频 成人影院 | 亚洲国产精品一区二区三区久久 | 免费一级毛片无毒不卡 | 日韩小视频| 国产在线高清不卡免费播放 | 欧美在线观看黄色 | 日本中文字幕一区二区 | 国产河南妇女毛片精品久久 | 毛片免费网站 | 自拍视频第一页 | 一本一本大道香蕉久在线精品 | 我要看欧美一级毛片 | 被黑人做的白浆直流在线播放 | 国产成人宗合 | 国产精品一区二区三区久久 | 特级女人十八毛片a级 | 国产乳摇福利视频在线观看 | 国产做爰免费视频观看 | 欧美一级毛片欧美毛片视频 | 久青草视频97国内免费影视 | 网址黄色 | 日本黄色一级毛片 | 日韩大片免费在线观看 | 国产区精品在线 | 91免费公开视频 | 网址大全在线免费观看 | 国产精品人成福利视频 | 日本久久综合网 | 久久婷婷激情 | 福利亚洲| 久久精品国产只有精品2020 | 看免费大片|