Spring Boot整合thymeleaf

添加thymeleaf依赖



    org.springframework.boot
    spring-boot-starter-thymeleaf


配置application.properties

#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end

org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类里面有默认的配置。
spring-boot很多配置都有默认配置:
比如默认页面映射路径为classpath:/templates/*.html
同样静态文件路径为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";
    }

}

引入文件
如图,引入相应的样式、图片和js文件,引入页面文件:

image.png

新建html文件

login.html






    
    

    INSPINIA | Login

    
    

    
    





    

IN+

Welcome to IN+

Perfectly designed and precisely prepared admin theme with over 50 pages with extra new web app views.

Login in. To see it in action.

Forgot password?

Do not have an account?

Create an account

Inspinia we app framework base on Bootstrap 3 © 2014

register.html






    
    

    INSPINIA | Register

    
    
    
    
    





    

IN+

Register to IN+

Create account to see it in action.

Already have an account?

Login

Inspinia we app framework base on Bootstrap 3 © 2014

运行结果

image.png

image.png

你可能感兴趣的:(Spring Boot整合thymeleaf)