本期視頻作了一個博客的首頁列表;html
內容簡介:springboot 集成 beetlsql;使用for循環,使用if控制語句,使用虛擬屬性,定義變量等等java
一塊兒學beetl目錄:https://my.oschina.net/u/1590490?tab=newest&catalogId=6214598mysql
做者:GKgit
引入依賴spring
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.5</version> </dependency>
application.properties中增長數據庫配置sql
spring.datasource.url=jdbc:mysql://mysql:3306/blog?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false&useInformationSchema=true spring.datasource.username=root spring.datasource.password=8975789757 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
增長數據源配置類數據庫
package com.ibeetl.blog.config; import com.zaxxer.hikari.HikariDataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import javax.sql.DataSource; /** * @author GavinKing * @ClassName: DBConfig * @Description: * @date 2018/11/18 */ @Configuration public class DBConfig { @Bean(name = "datasource") public DataSource datasource(Environment env) { HikariDataSource ds = new HikariDataSource(); ds.setJdbcUrl(env.getProperty("spring.datasource.url")); ds.setUsername(env.getProperty("spring.datasource.username")); ds.setPassword(env.getProperty("spring.datasource.password")); ds.setDriverClassName(env.getProperty("spring.datasource.driver-class-name")); return ds; } }
配置模板文件爲html 結尾,在application.properties中增長配置springboot
beetl.suffix=html
臨時變量:使用var 定義;相似js語法; 全局變量:整個模板都能訪問的變量;經過 template.bind("key",object)去定義 共享變量:全部的模板都能訪問的變量;經過app
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg); Map<String,Object> shared = new HashMap<String,Object>(); shared.put("name", "beetl"); gt.setSharedVars(shared);
去定義。 模板變量:至關於用一個變量表示一段模板或者代碼;ide
<% var content = { var c = "1234"; print(c); %> 模板其餘內容: <% }; %>
for循環,支持 for-in和for(exp,exp,exp)
for(blog in page.list){ .... } for(var i=0;i<page.list.~size){ page.list[i].... }
其餘循環語句
var i = 0; while(i<5){ print(i); i++; } //--------elsefor用法,若是for沒有進行循環時執行---------- var list = []; for(item in list){ }elsefor{ print("未有記錄"); }
條件語句
var a =true; var b = 1; if(a&&b==1){ }else if(a){ }else{ } //---------switch------- var b = 1; switch(b){ case 0: print("it's 0"); break; case 1: print("it's 1"); break; default: print("error"); } //---------select,更增強大的switch------- var b = 1; select(b){ case 0,1: print("it's small int"); case 2,3: print("it's big int"); default: print("error"); } //----------- var b = 1; select{ case b<1,b>10: print("it's out of range"); break; case b==1: print("it's 1"); break; default: print("error"); }
${date,"yyyy-MM-dd"}
這樣就能格式化時間了,嗯,超簡單
項目git地址:https://gitee.com/gavink/beetl-blog
視頻地址:下載下來會更清晰,說話比較慢,建議 1.2x倍速播放
百度網盤下載: https://pan.baidu.com/s/1LyxAxlKpVXgVjwSXIbzBuA 提取碼: 68im
bilibili (能夠調節清晰度): https://www.bilibili.com/video/av36278644/?p=2
博客目錄:https://my.oschina.net/u/1590490?tab=newest&catalogId=6214598