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

Thymeleaf怎么在SpringBoot中使用

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

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

1.引入依賴:

 <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

#是否開啟緩存,開發(fā)時可設置為false,默認為true
spring.thymeleaf.cache=true
#是否檢查模板是否存在,默認為true
spring.thymeleaf.check-template=true
#是否檢查模板位置是否存在,默認為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)建實體類和controller類

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("三國演義");
    Book b2 = new Book();
    b2.setId(2);
    b2.setAuthor("曹雪芹");
    b2.setName("紅樓夢");
    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>圖書列表</title>
</head>
<body>
<table border="1">
  <tr>
    <td>圖書編號</td>
    <td>圖書名稱</td>
    <td>圖書作者</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.結果:

Thymeleaf怎么在SpringBoot中使用

springboot是什么

springboot一種全新的編程規(guī)范,其設計目的是用來簡化新Spring應用的初始搭建以及開發(fā)過程,SpringBoot也是一個服務于框架的框架,服務范圍是簡化配置文件。

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

當前標題:Thymeleaf怎么在SpringBoot中使用
本文來源:http://chinadenli.net/article30/gicgpo.html

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

廣告

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

營銷型網(wǎng)站建設