欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Thymeleaf怎么在SpringBoot中使用

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)Thymeleaf怎么在SpringBoot中使用,文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

創(chuàng)新互聯(lián)建站專(zhuān)業(yè)為企業(yè)提供懷柔網(wǎng)站建設(shè)、懷柔做網(wǎng)站、懷柔網(wǎng)站設(shè)計(jì)、懷柔網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、懷柔企業(yè)網(wǎng)站模板建站服務(wù),十多年懷柔做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

1.引入依賴(lài):

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

2.application.properties

#是否開(kāi)啟緩存,開(kāi)發(fā)時(shí)可設(shè)置為false,默認(rèn)為true
spring.thymeleaf.cache=true
#是否檢查模板是否存在,默認(rèn)為true
spring.thymeleaf.check-template=true
#是否檢查模板位置是否存在,默認(rèn)為true
spring.thymeleaf.check-template-location=true
#模板文件編碼
spring.thymeleaf.encoding=UTF-8
#模板文件位置
spring.thymeleaf.prefix=classpath:/templates/
#Content-Type配置
spring.thymeleaf.servlet.content-type=text/html
#模板文件后綴
spring.thymeleaf.suffix=.html

3.創(chuàng)建實(shí)體類(lèi)和controller類(lèi)

public class Book {
  private Integer id;
  private String name;
  private String author;
  //省略getter/setter
}
@Controller
public class BookController {
  @GetMapping("/books")
  public ModelAndView books() {
    List<Book> books = new ArrayList<>();
    Book b1 = new Book();
    b1.setId(1);
    b1.setAuthor("羅貫中");
    b1.setName("三國(guó)演義");
    Book b2 = new Book();
    b2.setId(2);
    b2.setAuthor("曹雪芹");
    b2.setName("紅樓夢(mèng)");
    books.add(b1);
    books.add(b2);
    ModelAndView mv = new ModelAndView();
    mv.addObject("books", books);
    mv.setViewName("books");
    return mv;
  }
}

4.html文件:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>圖書(shū)列表</title>
</head>
<body>
<table border="1">
  <tr>
    <td>圖書(shū)編號(hào)</td>
    <td>圖書(shū)名稱(chēng)</td>
    <td>圖書(shū)作者</td>
  </tr>
  <tr th:each="book:${books}">
    <td th:text="${book.id}"></td>
    <td th:text="${book.name}"></td>
    <td th:text="${book.author}"></td>
  </tr>
</table>
</body>
</html>

5.結(jié)果:

Thymeleaf怎么在SpringBoot中使用

springboot是什么

springboot一種全新的編程規(guī)范,其設(shè)計(jì)目的是用來(lái)簡(jiǎn)化新Spring應(yīng)用的初始搭建以及開(kāi)發(fā)過(guò)程,SpringBoot也是一個(gè)服務(wù)于框架的框架,服務(wù)范圍是簡(jiǎn)化配置文件。

上述就是小編為大家分享的Thymeleaf怎么在SpringBoot中使用了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當(dāng)前標(biāo)題:Thymeleaf怎么在SpringBoot中使用
本文來(lái)源:http://www.chinadenli.net/article30/gicgpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)軟件開(kāi)發(fā)小程序開(kāi)發(fā)網(wǎng)站收錄企業(yè)網(wǎng)站制作關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)