国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

國(guó)際貿(mào)易網(wǎng)站排名最新網(wǎng)絡(luò)營(yíng)銷方式有哪些

國(guó)際貿(mào)易網(wǎng)站排名,最新網(wǎng)絡(luò)營(yíng)銷方式有哪些,營(yíng)銷推廣費(fèi)用預(yù)算,長(zhǎng)沙品牌網(wǎng)站建設(shè)Thymeleaf 支持 HTML 原型,可以讓前端工程師在瀏覽器中直接打開查看樣式,也可以讓后端工程師結(jié)合真實(shí)數(shù)據(jù)查看顯示效果 Thymeleaf 除了展示基本的 HTML ,進(jìn)行頁(yè)面渲染之外,也可以作為一個(gè) HTML 片段進(jìn)行渲染,例如我們?cè)凇?article class="baidu_pl">

Thymeleaf 支持 HTML 原型,可以讓前端工程師在瀏覽器中直接打開查看樣式,也可以讓后端工程師結(jié)合真實(shí)數(shù)據(jù)查看顯示效果
Thymeleaf 除了展示基本的 HTML ,進(jìn)行頁(yè)面渲染之外,也可以作為一個(gè) HTML 片段進(jìn)行渲染,例如我們?cè)谧鲟]件發(fā)送時(shí),可以使用 Thymeleaf 作為郵件發(fā)送模板

SpringBoot 提供了 Thymeleaf 自動(dòng)化配置解決方案:
這些默認(rèn)的配置我們幾乎不需要做任何更改就可以直接使用了。如果開發(fā)者有特殊需求,則可以在 application.properties 中配置以 spring.thymeleaf 開頭的屬性即可

①、配置類屬性:org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties

  • 首先通過 @ConfigurationProperties 注解,將 application.properties 前綴為 spring.thymeleaf 的配置和這個(gè)類中的屬性綁定
  • 前三個(gè) static 變量定義了默認(rèn)的編碼格式、視圖解析器的前綴、后綴等
  • 從前三行配置中,可以看出來,Thymeleaf 模板的默認(rèn)位置在 resources/templates 目錄下,默認(rèn)的后綴是 html
  • 這些配置,如果開發(fā)者不自己提供,則使用 默認(rèn)的,如果自己提供,則在 application.properties 中以 spring.thymeleaf 開始相關(guān)的配置
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {private staticfinal Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;public staticfinal String DEFAULT_PREFIX = "classpath:/templates/";public staticfinal String DEFAULT_SUFFIX = ".html";private boolean checkTemplate = true;private boolean checkTemplateLocation = true;private String prefix = DEFAULT_PREFIX;private String suffix = DEFAULT_SUFFIX;private String mode = "HTML";private Charset encoding = DEFAULT_ENCODING;private boolean cache = true;//...
}

②、配置類:org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration

  • 首先導(dǎo)入 ThymeleafProperties
  • 然后 @ConditionalOnClass 注解表示當(dāng)當(dāng)前系統(tǒng)中存在 TemplateMode 和 SpringTemplateEngine 類時(shí),當(dāng)前的自動(dòng)化配置類才會(huì)生效(即只要項(xiàng)目中引入了 Thymeleaf 相關(guān)的依賴,這個(gè)配置就會(huì)生效)
@Configuration
@EnableConfigurationProperties(ThymeleafProperties.class)
@ConditionalOnClass({ TemplateMode.class, SpringTemplateEngine.class })
@AutoConfigureAfter({ WebMvcAutoConfiguration.class, WebFluxAutoConfiguration.class })
publicclass ThymeleafAutoConfiguration {
}

由于 Thymeleaf 模板后綴為 .html,可以直接被瀏覽器打開

一、創(chuàng)建項(xiàng)目

在這里插入圖片描述

創(chuàng)建完成后,pom.xml 依賴如下:

<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>

二、創(chuàng)建Controller

@Controller
public class IndexController{@GetMapping("/index")public String index(Model model){List<User> users = new ArrayList<>();for(int i = 0; i < 10; i++){User u = new User();u.setId((long) i);u.setName("javaboy:" + i);u.setAddress("深圳:" + i);users.add(u);}//在 IndexController 中返回邏輯視圖名+數(shù)據(jù),邏輯視圖名為 indexmodel.addAttribute("users", users);return "index";}
}

需要在 resources/templates 目錄下提供一個(gè)名為 index.html 的 Thymeleaf 模板文件

<!DOCTYPE html><!--thymeleaf 名稱空間-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<table border="1"><tr><td>編號(hào)</td><td>用戶名</td><td>地址</td></tr><!--對(duì)model.addAttribute("users", users);進(jìn)行遍歷--><tr th:each="user : ${users}"><td th:text="${user.id}"></td><td th:text="${user.name}"></td><td th:text="${user.address}"></td></tr>
</table>
</body>
</html>

配置完成后,就可以啟動(dòng)項(xiàng)目了,訪問 /index 接口,就能看到集合中的數(shù)據(jù)了
在這里插入圖片描述

三、Thymeleaf 支持在 js 中直接獲取 Model 中的變量

@Controller
public class IndexController {@GetMapping("/index")public String index(Model model) {model.addAttribute("username", "李四");return"index";}
}
<script th:inline="javascript">var username = [[${username}]];console.log(username)
</script>

四、手動(dòng)渲染

一般在郵件發(fā)送時(shí)候有用,例如我在 resources/templates 目錄下新建一個(gè)郵件模板

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<p>hello 歡迎 <span th:text="${username}"></span>加入 XXX 集團(tuán),您的入職信息如下:</p>
<table border="1"><tr><td>職位</td><td th:text="${position}"></td></tr><tr><td>薪水</td><td th:text="${salary}"></td></tr>
</table>
<img src="http://www.javaboy.org/images/sb/javaboy.jpg" alt="">
</body>
</html>

這一個(gè) HTML 模板中,有幾個(gè)變量,要將這個(gè) HTML 模板渲染成一個(gè) String 字符串,再把這個(gè)字符串通過郵件發(fā)送出去

  1. 首先注入一個(gè) TemplateEngine 對(duì)象,這個(gè)對(duì)象就是在 Thymeleaf 的自動(dòng)化配置類中配置的(即當(dāng)我們引入 Thymeleaf 的依賴之后,這個(gè)實(shí)例就有了)
  2. 然后構(gòu)造一個(gè) Context 對(duì)象用來存放變量
  3. 調(diào)用 process 方法進(jìn)行渲染,該方法的返回值就是渲染后的 HTML 字符串,然后我們將這個(gè)字符串發(fā)送出去
@Autowired
TemplateEngine templateEngine;@Test
public void test1() throws MessagingException{Context context = new Context();context.setVariable("username", "javaboy");context.setVariable("position", "Java工程師");context.setVariable("salary", 99999);String mail = templateEngine.process("mail", context);//省略郵件發(fā)送
}
http://m.aloenet.com.cn/news/37654.html

相關(guān)文章:

  • 做網(wǎng)站虛擬主機(jī)怎么選擇技成培訓(xùn)網(wǎng)
  • 建網(wǎng)站的軟件優(yōu)幫云網(wǎng)站設(shè)計(jì)制作在哪里找
  • 網(wǎng)站商城系統(tǒng)建設(shè)方案新媒體運(yùn)營(yíng)主要做什么
  • 企業(yè)網(wǎng)站宣傳冊(cè)應(yīng)該哪個(gè)部門做it培訓(xùn)機(jī)構(gòu)
  • net開發(fā)的網(wǎng)站開發(fā)網(wǎng)站seo優(yōu)化排名
  • 溫州專業(yè)網(wǎng)站建設(shè)西安seo排名
  • 成都廣告公司排名前十名蘇州首頁(yè)排名關(guān)鍵詞優(yōu)化
  • 學(xué)做網(wǎng)站論壇vip賬戶蘇州網(wǎng)站建設(shè)書生
  • 無錫專業(yè)做網(wǎng)站站長(zhǎng)網(wǎng)站查詢工具
  • 高唐網(wǎng)站建設(shè)電子商務(wù)網(wǎng)站建設(shè)的步驟
  • 深圳微商城網(wǎng)站制作費(fèi)用網(wǎng)站seo排名優(yōu)化工具
  • 網(wǎng)站關(guān)鍵詞seo優(yōu)化怎么做怎樣進(jìn)行seo優(yōu)化
  • 個(gè)人軟件制作網(wǎng)站網(wǎng)站的優(yōu)化與推廣分析
  • 網(wǎng)站如果不在公安局備案怎樣百度seo關(guān)鍵詞排名查詢
  • 網(wǎng)頁(yè)抓取 wordpress西安自動(dòng)seo
  • php網(wǎng)站模塊如何編寫一個(gè)網(wǎng)站
  • 尋找手機(jī)網(wǎng)站建設(shè)北京優(yōu)化seo排名
  • 官網(wǎng)做的好看的網(wǎng)站有哪些設(shè)計(jì)網(wǎng)站排行
  • 宜春做網(wǎng)站公司網(wǎng)站seo優(yōu)化工具
  • 網(wǎng)站開發(fā)測(cè)試過程中文域名查詢官網(wǎng)
  • 阜寧做網(wǎng)站的公司新手怎么做電商
  • 自適應(yīng)網(wǎng)站做mip改造在哪里可以免費(fèi)自學(xué)seo課程
  • 哪家做公司網(wǎng)站互聯(lián)網(wǎng)廣告推廣好做嗎
  • 吧網(wǎng)站做軟件的軟件網(wǎng)絡(luò)銷售平臺(tái)怎么做
  • 做國(guó)際網(wǎng)站的流程廣州seo報(bào)價(jià)
  • java做網(wǎng)站百度客服怎么轉(zhuǎn)人工電話
  • 仿做唯品會(huì)網(wǎng)站黃岡便宜的網(wǎng)站推廣怎么做
  • pmp培訓(xùn)seo網(wǎng)站
  • 沈陽(yáng)網(wǎng)站搜索引擎優(yōu)化google推廣教程
  • 網(wǎng)頁(yè)版視頻網(wǎng)站建設(shè)需要多少錢百度sem推廣具體做什么