Spring Boot(4)整合thymeleaf

添加thymeleaf依賴

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

配置application.properties

#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#開發(fā)時關(guān)閉緩存,不然沒法看到實時頁面
spring.thymeleaf.cache=false
#thymeleaf end

org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties這個類里面有默認(rèn)的配置。
spring-boot很多配置都有默認(rèn)配置:
比如默認(rèn)頁面映射路徑為classpath:/templates/*.html
同樣靜態(tài)文件路徑為classpath:/static/

登錄頁面AdminController

package com.moxi.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @GetMapping("/login")
    public String login(Model model) {
        model.addAttribute("projectName", "MOXI");
        return "login";
    }

    @GetMapping("/register")
    public String register(Model model) {
        model.addAttribute("projectName", "MOXI");
        return "register";
    }

}

引入文件

如圖,引入相應(yīng)的樣式徽缚、圖片和js文件,引入頁面文件:

圖片.png

新建html文件

login.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    
    <title>INSPINIA | Login</title>
    
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet"/>
    
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
    
</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>
                <h2 class="logo-name" th:text="${projectName}">IN+</h2>
            </div>
            <h3 th:text="'Welcome to ' + ${projectName}">Welcome to IN+</h3>
            <p>Perfectly designed and precisely prepared admin theme with over 50 pages with extra new web app views.
                <!--Continually expanded and constantly improved Inspinia Admin Them (IN+)-->
            </p>
            <p>Login in. To see it in action.</p>
            <form class="m-t" role="form" action="index.html">
                <div class="form-group">
                    <input type="email" class="form-control" placeholder="Username" required=""/>
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" placeholder="Password" required=""/>
                </div>
                <button type="submit" class="btn btn-primary block full-width m-b">Login</button>
                <a th:href="@{register}" href="#"><small>Forgot password?</small></a>
                <p class="text-muted text-center"><small>Do not have an account?</small></p>
                <a class="btn btn-sm btn-white btn-block"  th:href="@{register}" href="register.html">Create an account</a>
            </form>
            <p class="m-t"> <small>Inspinia we app framework base on Bootstrap 3 ? 2014</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    
    
    <script th:src="@{/js/jquery-2.1.1.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>

</body>

</html>

register.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <title>INSPINIA | Register</title>

    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/css/plugins/iCheck/custom.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>

</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen   animated fadeInDown">
        <div>
            <div>
                <h2 class="logo-name" th:text="${projectName}">IN+</h2>
            </div>
            <h3 th:text="'Register to ' + ${projectName}">Register to IN+</h3>
            <p>Create account to see it in action.</p>
            <form class="m-t" role="form" action="login.html">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Name" required=""/>
                </div>
                <div class="form-group">
                    <input type="email" class="form-control" placeholder="Email" required=""/>
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" placeholder="Password" required=""/>
                </div>
                <div class="form-group">
                        <div class="checkbox i-checks"><label> <input type="checkbox"/><i></i> Agree the terms and policy </label></div>
                </div>
                <button type="submit" class="btn btn-primary block full-width m-b">Register</button>

                <p class="text-muted text-center"><small>Already have an account?</small></p>
                <a class="btn btn-sm btn-white btn-block" th:href="login" href="login.html">Login</a>
            </form>
            <p class="m-t"> <small>Inspinia we app framework base on Bootstrap 3 ? 2014</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    <script src="js/jquery-2.1.1.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- iCheck -->
    <script src="js/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(document).ready(function(){
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
</body>

</html>

運行結(jié)果

圖片.png
圖片.png

項目地址

https://github.com/daleiwang/moxi

thymeleaf參考

http://www.reibang.com/p/ed9d47f92e37(模板)
http://blog.csdn.net/quuqu/article/details/52511933(基礎(chǔ))

Spring Boot(1)工具安裝:

http://www.reibang.com/p/fb6ed37c90eb

Spring Boot(2)新建Spring Boot工程

http://www.reibang.com/p/00fd73f515f6

Spring Boot(3)整合Mybatis

http://www.reibang.com/p/8401e9304fa0

Spring Boot(4)整合thymeleaf

http://www.reibang.com/p/8d2cc7207fb2

Spring Boot(5)一個極簡且完整的后臺框架

http://www.reibang.com/p/923d26d705ed

Spring Boot(6)jar方式打包發(fā)布

http://www.reibang.com/p/9cf6faa8595e

Spring Boot(7)war方式打包發(fā)布

http://www.reibang.com/p/ae170a58f88c

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末拭卿,一起剝皮案震驚了整個濱河市纯续,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌补疑,老刑警劉巖弧蝇,帶你破解...
    沈念sama閱讀 219,110評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件碳褒,死亡現(xiàn)場離奇詭異折砸,居然都是意外死亡,警方通過查閱死者的電腦和手機沙峻,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評論 3 395
  • 文/潘曉璐 我一進(jìn)店門睦授,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人专酗,你說我怎么就攤上這事睹逃。” “怎么了祷肯?”我有些...
    開封第一講書人閱讀 165,474評論 0 356
  • 文/不壞的土叔 我叫張陵沉填,是天一觀的道長。 經(jīng)常有香客問我佑笋,道長翼闹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,881評論 1 295
  • 正文 為了忘掉前任蒋纬,我火速辦了婚禮猎荠,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蜀备。我一直安慰自己关摇,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,902評論 6 392
  • 文/花漫 我一把揭開白布碾阁。 她就那樣靜靜地躺著输虱,像睡著了一般。 火紅的嫁衣襯著肌膚如雪脂凶。 梳的紋絲不亂的頭發(fā)上宪睹,一...
    開封第一講書人閱讀 51,698評論 1 305
  • 那天,我揣著相機與錄音蚕钦,去河邊找鬼亭病。 笑死,一個胖子當(dāng)著我的面吹牛嘶居,可吹牛的內(nèi)容都是我干的罪帖。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼邮屁,長吁一口氣:“原來是場噩夢啊……” “哼整袁!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起樱报,我...
    開封第一講書人閱讀 39,332評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎泞当,沒想到半個月后迹蛤,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,796評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,968評論 3 337
  • 正文 我和宋清朗相戀三年盗飒,在試婚紗的時候發(fā)現(xiàn)自己被綠了嚷量。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,110評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡逆趣,死狀恐怖蝶溶,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情宣渗,我是刑警寧澤抖所,帶...
    沈念sama閱讀 35,792評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站痕囱,受9級特大地震影響田轧,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜鞍恢,卻給世界環(huán)境...
    茶點故事閱讀 41,455評論 3 331
  • 文/蒙蒙 一傻粘、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧帮掉,春花似錦弦悉、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至盅称,卻和暖如春肩祥,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背缩膝。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評論 1 272
  • 我被黑心中介騙來泰國打工混狠, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人疾层。 一個月前我還...
    沈念sama閱讀 48,348評論 3 373
  • 正文 我出身青樓将饺,卻偏偏與公主長得像,于是被迫代替她去往敵國和親痛黎。 傳聞我的和親對象是個殘疾皇子予弧,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,047評論 2 355

推薦閱讀更多精彩內(nèi)容