Spring Boot整合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ā)時(shí)關(guān)閉緩存,不然沒法看到實(shí)時(shí)頁面
spring.thymeleaf.cache=false
#thymeleaf end

org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties這個(gè)類里面有默認(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文件熄浓,引入頁面文件:

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

運(yùn)行結(jié)果

image.png

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末情臭,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌俯在,老刑警劉巖竟秫,帶你破解...
    沈念sama閱讀 221,273評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異朝巫,居然都是意外死亡鸿摇,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門劈猿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來拙吉,“玉大人,你說我怎么就攤上這事揪荣】昵” “怎么了?”我有些...
    開封第一講書人閱讀 167,709評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵仗颈,是天一觀的道長佛舱。 經(jīng)常有香客問我,道長挨决,這世上最難降的妖魔是什么请祖? 我笑而不...
    開封第一講書人閱讀 59,520評(píng)論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮脖祈,結(jié)果婚禮上肆捕,老公的妹妹穿的比我還像新娘。我一直安慰自己盖高,他們只是感情好慎陵,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,515評(píng)論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著喻奥,像睡著了一般席纽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上撞蚕,一...
    開封第一講書人閱讀 52,158評(píng)論 1 308
  • 那天润梯,我揣著相機(jī)與錄音,去河邊找鬼诈豌。 笑死仆救,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的矫渔。 我是一名探鬼主播彤蔽,決...
    沈念sama閱讀 40,755評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼庙洼!你這毒婦竟也來了顿痪?” 一聲冷哼從身側(cè)響起镊辕,我...
    開封第一講書人閱讀 39,660評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蚁袭,沒想到半個(gè)月后征懈,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,203評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡揩悄,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,287評(píng)論 3 340
  • 正文 我和宋清朗相戀三年卖哎,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片删性。...
    茶點(diǎn)故事閱讀 40,427評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡亏娜,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蹬挺,到底是詐尸還是另有隱情维贺,我是刑警寧澤,帶...
    沈念sama閱讀 36,122評(píng)論 5 349
  • 正文 年R本政府宣布巴帮,位于F島的核電站溯泣,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏榕茧。R本人自食惡果不足惜垃沦,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,801評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望用押。 院中可真熱鬧栏尚,春花似錦、人聲如沸只恨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽官觅。三九已至,卻和暖如春阐污,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評(píng)論 1 272
  • 我被黑心中介騙來泰國打工卦羡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留宫患,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,808評(píng)論 3 376
  • 正文 我出身青樓手幢,卻偏偏與公主長得像捷凄,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子围来,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,440評(píng)論 2 359

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