码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot整合LayUI和Thymeleaf制作简单登录页面

时间:2020-01-26 23:50:38      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:简单的   efi   framework   oca   private   static   写视图   odi   了解   

前面已经学习过SpringBoot整合Thymeleaf,这次主要把上次提到的简单登录界面用博文形式写出来

记录一个小Demo的学习,如果没看过SpringBoot整合Thymeleaf可以看一下SpringBoot整合Thymeleaf(三)

先上页面效果图:

技术图片

Demo所涉及的知识点

1.SpringBoot请求映射

2.static和templates静态资源映射

只要简单了解这两个知识点,就可以做出简单的登录的页面

Demo所涉及的目录结构图

技术图片

Demo所涉及的Pom文件的主要依赖

    <dependencies>
        <!--thymeleaf模板引擎依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--Springboot-Web开发依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

Demo编码思路及知识点记录

1.引入Maven所需要的thymeleaf和web依赖

2.编写视图层LoginController,添加请求访问 /,/login.html的映射规则

3.通过资源文件夹形式引入layui框架的静态资源(CSS,JS)及个性定制的(CSS,JS,IMAGE),主要通过th:src,th:href两个属性引入

编写视图层LoginController添加/,/login.html的映射规则

@Controller
public class LoginController {
    @RequestMapping({"/","login.html"})
    public String Login(){
        return "login";
    }
}

这里记录一下,SpringBoot会根据return "login";的返回值,自动找到类路径下的templates文件夹的login.html,具体的前后缀组装原则,可以在ThymeleafProperties,双击shift快捷键,输入“ThymeleafProperties”,关键的代码如下

public class ThymeleafProperties {
    private static final Charset DEFAULT_ENCODING;
    public static final String DEFAULT_PREFIX = "classpath:/templates/"; //前缀
    public static final String DEFAULT_SUFFIX = ".html";//后缀
    private boolean checkTemplate = true;
    private boolean checkTemplateLocation = true;
    private String prefix = "classpath:/templates/";//类路径下的templates文件夹
    private String suffix = ".html";
    private String mode = "HTML";
}

引入layui框架的静态资源(CSS,JS)及个性定制的(CSS,JS,IMAGE)

LayUI框架是一个前端框架,可以快速搭建一个简约页面,可以到官网下载最新的版本,具体的静态资源时放在类路径的static文件下,因为这是SpringBoot约定好的静态资源文件存放位置之一(另外还有四个文件夹可以存放)

技术图片

最后就是在html页面,引用thymeleaf的使用,往页面中引入这些CSS,JS,IMAGE ,主要用到th:src,th:href两个属性

    <!--css -->
    <link rel="stylesheet"  th:href="@{/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/css/login.css}"/>
    <!--images -->
    <img  th:src="@{/images/01.jpg}"/>
    <img  th:src="@{/images/03.jpg}"/>
    <!-- Layui Js -->
    <script type="text/javascript" th:src="@{/layui/layui.js}"></script>

Demo及静态页面下载

登录页面源代码:基于Layui简约登录界面

??Github: springboot-themeleaf-layui

SpringBoot整合LayUI和Thymeleaf制作简单登录页面

标签:简单的   efi   framework   oca   private   static   写视图   odi   了解   

原文地址:https://www.cnblogs.com/codeluojay/p/12235038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!