企业级信息系统开发讲课笔记4.9 Thymeleaf模板引擎

news2024/9/29 15:29:12

文章目录

  • 零、学习目标
  • 一、Spring Boot支持的视图技术
  • 二、Thymeleaf基本语法
    • 1、Thymeleaf常用标签
    • 2、Thymeleaf主要语法
    • 3、Thymeleaf内置对象
    • 4、Thymeleaf模板基本配置
  • 三、Spring Boot整合Thymeleaf
    • 1、创建Spring Boot项目ThymeleafDemo
    • 2、在全局配置文件里配置Thymeleaf属性
    • 3、创建登录控制器LoginController
    • 4、创建模板文件,获取控制器传来的动态数据
    • 5、启动项目,访问http://localhost:8080/toLoginPage
    • 课堂练习
  • 四、Spring Boot集成Bootstrap
    • (一)集成Bootstrap
      • 1、引用在线文档的方式
      • 2、下载Bootstrap并引用的方式
    • (二)编写登录页面login.html
      • 1、集成Bootstrap
      • 2、编写登录页面
      • 3、启动项目,访问http://localhost:8080/toLoginPage
      • 4、用户名和密码非空校验
    • (三)控制器编写登录验证方法
    • (四)编写登录成功与失败的模板页面
      • 1、编写登录成功页面success.html
      • 2、编写登录失败页面failure.html
    • (五)启动项目,测试效果
  • 五、Thymeleaf访问模型里的数据
    • (一)页面访问Model里的实体数据
      • 1、创建个人实体类 - Person
      • 2、在登录控制器里添加获取个人信息方法
      • 3、创建显示个人信息的模板页面
      • 3、启动应用,测试效果
    • (二)页面访问Model里的列表数据
      • 1、创建商品实体类 - Product
      • 2、创建商品控制器 - ProductController
      • 3、创建显示商品信息页面 - products.html
      • 4、启动应用,查看效果
      • 5、对模型里的数据进行判断
    • (三)页面里JavaScript访问模型里的数据
      • 1、显示个人信息页面
      • 2、显示商品列表信息
  • 六、课后作业
    • 任务:利用MyBatis、JPA或Redis技术,从数据库读取用户信息进行验证用户是否登录成功

零、学习目标

  1. 了解Spring Boot支持的视图技术
  2. 掌握Thymeleaf常用标签
  3. 掌握Thymeleaf标准表达式
  4. 掌握Thymeleaf基本使用
  5. 掌握使用Thymeleaf完成数据的页面展示

一、Spring Boot支持的视图技术

  • Spring Boot框架为简化项目的整体开发,对一些常用的视图技术实现了整合支持,并主要推荐整合模板引擎技术来实现前端页面的动态化内容。
  • Spring Boot可整合的模板引擎技术
  1. FreeMarker
  2. Groovy
  3. Thymeleaf
  4. Mustache
    ……

二、Thymeleaf基本语法

  • 相关语法 ,请学习《thymeleaf_3.0.5_中文参考手册.pdf》 提取码:fqpu

1、Thymeleaf常用标签

th:标签说明
th:insert页面片段包含(类似JSP中的include标签)
th:replace页面片段包含(类似JSP中的include标签)
th:each元素遍历(类似JSP中的c:forEach标签)
th:if条件判断,如果为真
th:unless条件判断,如果为假
th:switch条件判断,进行选择性匹配
th:case条件判断,进行选择性匹配
th:object变量声明
th:with变量声明
th:attr通用属性修改
th:attrprepend通用属性修改,将计算结果追加前缀到现有属性值
th:attrappend通用属性修改,将计算结果追加后缀到现有属性值
th:value属性值修改,指定标签属性值
th:href用于设定链接地址
th:src用于设定链接地址
th:text用于指定标签显示的文本内容
th:utext用于指定标签显示的文本内容,对特殊标签不转义
th:fragment声明片段
th:remove移除片段

2、Thymeleaf主要语法

说明表达式语法作用
变量表达式${...}获取上下文中的变量值
选择变量表达式*{...}用于从被选定对象获取属性值
消息表达式#{...} 用于Thymeleaf模板页面国际化内容的动态替换和展示
链接URL表达式@{...}用于页面跳转或者资源的引入
片段表达式~{...}用来标记一个片段模板,并根据需要移动或传递给其他模板

3、Thymeleaf内置对象

  • #ctx:上下文对象
  • #vars:上下文变量
  • #locale:上下文区域设置
  • #request:(仅限Web Context)HttpServletRequest对象
  • #response:(仅限Web Context)HttpServletResponse对象
  • #session:(仅限Web Context)HttpSession对象
  • #servletContext:(仅限Web Context)ServletContext对象

4、Thymeleaf模板基本配置

  • 在Spring Boot项目中使用Thymeleaf模板,必须保证引入Thymeleaf依赖
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
  • 在全局配置文件中配置Thymeleaf模板的一些参数。如设置模板缓存、模板编码、模板样式、指定模板页面存放路径、指定模板页面名称的后缀
spring.thymeleaf.cache = true
spring.thymeleaf.encoding = UTF-8   
spring.thymeleaf.mode = HTML5   
spring.thymeleaf.prefix = classpath:/templates/  
spring.thymeleaf.suffix = .html   
  • 关于Thymeleaf,可以参看博主两年前编写的《Thymeleaf模板引擎入门》
  • 关于Bootstrap,可以参看博主两年前编写的《前端学习笔记:Bootstrap框架入门》
  • 下面我们会一起来学习Spring Boot如何整合Thymeleaf与Bootstrap,实现一个简单的登录页面

三、Spring Boot整合Thymeleaf

1、创建Spring Boot项目ThymeleafDemo

  • 设置项目元数据
    在这里插入图片描述

  • 添加项目依赖
    在这里插入图片描述

  • 设置项目名称与保存位置
    在这里插入图片描述

  • 完成项目初始化工作
    在这里插入图片描述

  • 查看pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.hw.lesson09</groupId>
    <artifactId>thymeleafdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>ThymeleafDemo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

2、在全局配置文件里配置Thymeleaf属性

在这里插入图片描述

#缓存配置,默认即是true,开发阶段设置为false
spring.thymeleaf.cache = false
#设置模板使用的编码为utf-8
spring.thymeleaf.encoding = UTF-8
#指定为模板使用的模式为html5,默认html
spring.thymeleaf.mode = HTML5
#指定前缀,默认位置为/templates/,可以修改成其它位置
spring.thymeleaf.prefix = classpath:/templates/
#指定模板文件后缀,默认值为.html,可以修改成其它值
spring.thymeleaf.suffix = .html
  • Thymeleaf页面缓存设置,默认为true,开发中方便调试应设置为false,上线稳定后应保持默认true

3、创建登录控制器LoginController

  • 在net.hw.lesson09包里创建controller子包
  • 在controller子包里创建LoginController控制器
  • 用于前端模板页面动态数据替换效果的测试
    在这里插入图片描述
package net.hw.lesson09.controller;

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

import java.util.Calendar;

/**
 * 功能:登录控制器
 * 作者:华卫
 * 日期:2020年08月14日
 */
@Controller
public class LoginController {
    /**
     * 通过请求“toLoginPage”跳转到templates目录下的
     * login页面,并把当前年份数据保存到模型对象中
     */
    @GetMapping("toLoginPage")
    public String toLoginPage(Model model){
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "login"; // 返回逻辑页面视图名称
    }
}

4、创建模板文件,获取控制器传来的动态数据

  • 在templates目录下创建模板文件login.html
    在这里插入图片描述

  • h3标签中通过th:text引入了后台动态传递过来的当前年份currentYear

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
    <span th:text="${currentYear}">今年</span> -
    <span th:text="${currentYear} + 1">明年</span>
</body>
</html>
  • 静态访问模板文件,将显示默认值,而不会显示后台传来的动态数据
    在这里插入图片描述

5、启动项目,访问http://localhost:8080/toLoginPage

  • 启动项目
    在这里插入图片描述

  • 在浏览器里访问http://localhost:8080/toLoginPage
    在这里插入图片描述

课堂练习

  • 创建用户实体类 - User
    在这里插入图片描述

  • 在登录控制器的toLoginPage()方法里,创建用户对象,放入模型对象

  • 在登录页面显示用户信息,查看运行效果
    在这里插入图片描述

  • 改变用户信息显示方式
    在这里插入图片描述

四、Spring Boot集成Bootstrap

  • Bootstrap4教程:https://www.runoob.com/bootstrap4/bootstrap4-tutorial.html
    在这里插入图片描述
  • 注意:Bootstrap3和Bootstrap4两版本有较大差异

(一)集成Bootstrap

1、引用在线文档的方式

  • 在模板文件中直接引用以下文件
    在这里插入图片描述
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>

2、下载Bootstrap并引用的方式

链接:https://pan.baidu.com/s/1vEmjeGTdM9jERbXPU4bmAw 提取码:qgo9
在这里插入图片描述

  • 解压缩到bootstrap-4.0.0目录
    在这里插入图片描述

  • 将bootstrap-4.0.0目录拷贝项目的static目录
    在这里插入图片描述
    在这里插入图片描述

(二)编写登录页面login.html

1、集成Bootstrap

在这里插入图片描述

2、编写登录页面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>  
</head>
<body>
<div class="col-6 m-auto" style="margin-top:30px!important;">
    <div class="text-center">
        <span th:text="${currentYear}">今年</span> -
        <span th:text="${currentYear} + 1">明年</span>
    </div>
    <div class="border border-info bg-light p-2" style="border-radius: 5px">
        <form action="/login" method="post">
            <h3 class="text-center">用户登录</h3>
            <div class="mt-1">
                <input type="text" id="username" name="username" class="form-control" placeholder="输入用户名" autofocus>
            </div>
            <div class="mt-1">
                <input type="password" id="password" name="password" class="form-control" placeholder="输入密码">
            </div>
            <div class="checkbox text-center">
                <label>
                    <input class="form-check-input text-center" type="checkbox">记住我
                </label>
            </div>
            <div>
                <button class="btn btn-lg btn-primary btn-block" id="login" type="submit">登录</button>
            </div>
        </form>
    </div>
</div>
</body>
</html>
  • <div class="col-6 m-auto" style="margin-top:30px!important;"> 分区占窗口一半宽度(水平方向按12个单位平分)、水平居中、顶边距30个像素
  • <div class="border border-info bg-light p-2" style="border-radius: 5px"> 设置边框(边框色、背景、内边距、圆角)
  • <div class="mt-1"> 设置上外边距为1个单位
  • <h3 class="text-center">用户登录</h3> 设置文本居中显示

3、启动项目,访问http://localhost:8080/toLoginPage

在这里插入图片描述

4、用户名和密码非空校验

  • 留待大家自行完成
    在这里插入图片描述

(三)控制器编写登录验证方法

在这里插入图片描述
在这里插入图片描述

@PostMapping("/login")                                                          
public String login(HttpServletRequest request, Model model) {                 
    // 获取表单提交的用户名与密码                                                           
    String username = request.getParameter("username");                        
    String password = request.getParameter("password");                        
    // 判断用户是否登录成功(假设合法用户名为howard,密码为903213)                                    
    if (username.equals("howard") && password.equals("903213")) {              
        model.addAttribute("loginMsg", "恭喜,用户登录成功~");                          
        return "success";                                                      
    } else {                                                                   
        model.addAttribute("loginMsg", "遗憾,用户登录失败~");                          
        return "failure";                                                      
    }                                                                          
}                                                                              

(四)编写登录成功与失败的模板页面

1、编写登录成功页面success.html

在这里插入图片描述

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>登录成功</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>
</head>
<body>
<div class="col-6 text-center m-auto border-info border p-3 bg-light" style="margin-top:50px!important;">
    <p th:text="${loginMsg}" class="text-success"></p>
</div>
</body>
</html>

2、编写登录失败页面failure.html

在这里插入图片描述

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>登录失败</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>
</head>
<body>
<div class="col-6 text-center m-auto border-warning border p-3 bg-light" style="margin-top:50px!important;">
    <p th:text="${loginMsg}" class="text-danger"></p>
</div>
</body>
</html>

(五)启动项目,测试效果

  • 启动项目后,在浏览器里访问http://localhost:8080/toLoginPage
    在这里插入图片描述

  • 输入正确的用户名和密码(howard : 903213)
    在这里插入图片描述

  • 输入其它用户名或密码
    在这里插入图片描述

五、Thymeleaf访问模型里的数据

(一)页面访问Model里的实体数据

1、创建个人实体类 - Person

在这里插入图片描述

package net.hw.lesson09.bean;

/**
 * 功能:个人实体类
 * 作者:华卫
 * 日期:2021年05月24日
 */
public class Person {
    private int id;
    private String name;
    private String gender;
    private int age;
    private String telephone;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                ", telephone='" + telephone + '\'' +
                '}';
    }
}

2、在登录控制器里添加获取个人信息方法

在这里插入图片描述

3、创建显示个人信息的模板页面

在这里插入图片描述

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>
</head>
<body>
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">显示个人信息</h3>
    </div>
    <div class="panel-body">
        编号:<span th:text="${person.id}">1</span><br/>
        姓名:<span th:text="${person.name}">娃哈哈</span><br/>
        性别:<span th:text="${person.gender}"></span><br/>
        年龄:<span th:text="${person.age}">20</span><br/>
        电话:<span th:text="${person.telephone}">15878789056</span><br/>
    </div>
</div>
</body>
</html>

3、启动应用,测试效果

  • 启动应用
    在这里插入图片描述
  • 访问http://localhost:8080/getPerson
    在这里插入图片描述
  • 问题:Bootstrap的面板样式没有起作用。
  • 以在线方式导入Bootstrap 3,就可以看到面板效果
    在这里插入图片描述
  • 说明:Bootstrap从4.x开始,用Card替换了Panel
    在这里插入图片描述
  • 修改person.html,采用card组件
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>
</head>
<body>
<div class="card">
    <div class="card-header" style="background-color:royalblue">
        <h4 class="card-title" style="color:white">显示个人信息</h4>
    </div>
    <div class="card-body">
        编号:<span th:text="${person.id}">1</span><br/>
        姓名:<span th:text="${person.name}">娃哈哈</span><br/>
        性别:<span th:text="${person.gender}"></span><br/>
        年龄:<span th:text="${person.age}">20</span><br/>
        电话:<span th:text="${person.telephone}">15878789056</span><br/>
    </div>
    <div class="card-footer">
        信工院2021.05.24
    </div>
</div>
</body>
</html>
  • 启动应用,查看效果
    在这里插入图片描述

(二)页面访问Model里的列表数据

1、创建商品实体类 - Product

在这里插入图片描述

package net.hw.lesson09.bean;

/**
 * 功能:商品实体类
 * 作者:华卫
 * 日期:2021年05月24日
 */
public class Product {
    private int id;
    private String name;
    private double price;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}

2、创建商品控制器 - ProductController

在这里插入图片描述

package net.hw.lesson09.controller;

import net.hw.lesson09.bean.Product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能:商品控制器
 * 作者:华卫
 * 日期:2021年05月24日
 */
@Controller
public class ProductController {
    @GetMapping("/getProducts")
    public String getProducts(Model model) {
        // 创建商品列表
        List<Product> products = new ArrayList<>();
        
        Product product = new Product();
        product.setId(1);
        product.setName("海尔电视机");
        product.setPrice(2500);
        products.add(product);

        product = new Product();
        product.setId(2);
        product.setName("小米手机");
        product.setPrice(2000);
        products.add(product);

        product = new Product();
        product.setId(3);
        product.setName("华为电脑");
        product.setPrice(5000);
        products.add(product);
        
        // 将商品列表写入模型
        model.addAttribute("products", products);
        // 返回逻辑视图名
        return "products";
    }
}

3、创建显示商品信息页面 - products.html

在这里插入图片描述

<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>商品信息</title>
    <link th:href="@{/bootstrap-4.0.0/css/bootstrap.css}" rel="stylesheet">
    <javascript th:src="@{/bootstrap-4.0.0/js/jquery-3.4.1.min.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.bundle.js}"></javascript>
    <javascript th:src="@{/bootstrap-4.0.0/js/bootstrap.js}"></javascript>
</head>
<body>
<div class="card">
    <div class="card-header" style="background-color:royalblue">
        <h4 class="card-title" style="color:white">显示商品信息</h4>
    </div>
    <div class="card-body">
        <ul class="list-group">
            <li class="list-group-item" th:each="product:${products}">
                编号:<span th:text="${product.id}">1</span><br/>
                名称:<span th:text="${product.name}">洗衣机</span><br/>
                单价:<span th:text="${product.price}">1000</span><br/>
            </li>
        </ul>
    </div>
    <div class="card-footer">
        信工院2021.05.24
    </div>
</div>
</body>
</html>

4、启动应用,查看效果

  • 启动应用
    在这里插入图片描述
  • 访问http://localhost:8080/getProducts
    在这里插入图片描述

5、对模型里的数据进行判断

  • 通过${not #lists.isEmpty(products)}表达式判断products是否为空。Thymeleaf支持>、<、>=、<=、==、!=作为比较条件,同时也支持SpringEL表达式语言用于条件中。
  • 修改显示商品信息页面
    在这里插入图片描述
  • 修改商品控制器
    在这里插入图片描述
  • 启动应用,查看效果
    在这里插入图片描述

(三)页面里JavaScript访问模型里的数据

1、显示个人信息页面

  • 添加脚本,修改代码
    在这里插入图片描述
  • 启动应用,查看效果
    在这里插入图片描述
  • 通过 th:inline="javascript"添加到script标签,这样JavaScript即可访问model中属性。通过[[${属性}]]格式获得实际的值。

2、显示商品列表信息

  • 添加脚本,修改代码
    在这里插入图片描述
  • 修改商品控制器
    在这里插入图片描述
  • 启动应用,查看效果
    在这里插入图片描述
  • 优化代码,采用循环结构显示商品列表
    在这里插入图片描述

六、课后作业

任务:利用MyBatis、JPA或Redis技术,从数据库读取用户信息进行验证用户是否登录成功

  • 增加用户表t_user
  • 创建用户实体类
  • 创建数据访问接口
  • 修改控制器login()方法

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/636642.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

简化本地Feign调用,老手教你这么玩

原创&#xff1a;微信公众号 码农参上&#xff0c;欢迎分享&#xff0c;转载请在文章头部保留出处&#xff0c;侵权必究 哈喽大家好啊&#xff0c;我是Hydra。 在平常的工作中&#xff0c;OpenFeign作为微服务间的调用组件使用的非常普遍&#xff0c;接口配合注解的调用方式突…

ChatGPT涉及的法律风险综述

ChatGPT&#xff08;Chat Generative Pre-trained Transformer&#xff09;&#xff0c;是OpenAI研发的聊天机器人程序&#xff0c;于2022年11月30日发布。从发布的那一刻至今&#xff0c;ChatGPT一直受到各界的广泛关注。作为人工智能技术驱动的自然语言处理工具&#xff0c;它…

一种简单的文本监督语义分割框架

文章目录 A Simple Framework for Text-Supervised Semantic Segmentation摘要本文方法动机Locality-Driven Alignment&#xff08;LoDA&#xff09;SimSeg Framework 实验结果 A Simple Framework for Text-Supervised Semantic Segmentation 摘要 文本监督语义分割是一个新…

音频转文字工具都有哪些?分享三款好用的录音转文字软件

对于许多人来说&#xff0c;录音已经成为了记录重要信息的常用方法。但是&#xff0c;在实际应用中&#xff0c;往往会遇到如何将这些录音内容转换为文字记录的挑战。这是一个备受关注的问题。那么&#xff0c;录音如何转为文字呢&#xff1f;这篇文章就来给你推荐几个非常好用…

yolov5 的 mAP 和 召回率很低,但是精准率 AP还可以

可能的原因&#xff1a; 标注问题&#xff0c; 检查图片没有txt&#xff0c;导致有正样本的图片&#xff0c;被认为是背景&#xff0c;召回率降低。是否是中文路径, opencv这个cv2.imread不能读取中文图像。 改成这样就行。

预约按摩系统平台开发,常见问题解答

预约按摩平台系统常见问题&#xff1a; 预约流程&#xff1a;按摩系统提供简单易用的预约流程&#xff0c;用户只需要提供必要的信息即可完成预约&#xff0c;同时也可以随时修改或取消预约。 付款方式&#xff1a;按摩系统支持线上和线下支付方式&#xff0c;其中线上支付采用…

使用python-docx在文档中插入图片

在文档中添加图片的方法如下&#xff1a; from docx import Document from docx.shared import Inches, Cmdocument Document() document.add_heading(大标题, 0)# 新建word文档 p document.add_paragraph("下面插入图片&#xff1a;")document.add_picture(test_…

电力监控系统在电力系统中的应用

安科瑞虞佳豪 一年一度高考和中考即将来临&#xff0c;日前&#xff0c;国网咸丰县供电公司积极有序开展保电工作&#xff0c;全面进入“高考保供电”模式。 为全力保障高考期间供电安全&#xff0c;国网咸丰县供电公司将大水线供电线路采取分流运输方式&#xff0c;将除春晖…

IDEA之Mybatis Log Plugin的使用

Mybatis Log Plugin是一个用于记录Mybatis SQL语句执行情况的插件&#xff0c;帮助开发人员方便地追踪和分析Mybatis执行的SQL语句&#xff0c;从而更容易地找出程序中存在的问题和优化SQL语句的性能。 Mybatis Log Plugin可以以日志的形式记录Mybatis执行的SQL语句、执行时间…

win批量取消快速访问固定

win批量取消快速访问固定

Hibernate框架【五】——基本映射——多对多映射

系列文章目录 Hibernate框架【三】——基本映射——一对一映射 Hibernate框架【四】——基本映射——多对一和一对多映射 基本映射——多对多映射 系列文章目录前言一、多对多映射是什么&#xff1f;二、hibernate多对多关联映射&#xff08;单向&#xff09;1.实体结构2.示意…

Flink Table/Sql自定义Kudu Sink实战(其它Sink可参考)

目录 1. 背景2. 原理3. 通过Trino创建Kudu表4. FlinkKuduTableSinkProject项目4.1 pom.xml4.2 FlinkKuduTableSinkFactory.scala4.3 META-INF/services4.4 FlinkKuduTableSinkTest.scala测试文件 5. 查看Kudu表数据 1. 背景 使用第三方的org.apache.bahir flink-connector-ku…

​2023年湖北企业人力资源管理师报考条件是什么?启程别告诉你

2023年湖北企业人力资源管理师报考条件是什么&#xff1f;启程别告诉你 2019年国家就取消了企业人力资源管理师国家职业资格考试&#xff0c;现在是改革为职业技能等级认证&#xff0c;由人社部监管的第三方组织机构组织考试和颁发证书&#xff0c;那改革后的企业人力资源管理师…

创建镜像-dockerfile

Docker 镜像的创建 创建镜像有三种方法&#xff1a; 1.基于已有镜像创建、 2.基于本地模板创建 3.基于Dockerfile创建。 基于现有镜像创建 首先启动一个镜像&#xff0c;在容器里做修改 docker create -it centos:7 /bin/bash然后将修改后的容器提交为新的镜像&#xff…

在JavaScript中的数据结构(队列)

文章目录 什么是队列&#xff1f;创建队列新建队列队列可用的方法队列添加元素队列移除元素队列查看元素查看队列头元素检查队列是否为空检查队列的长度打印队列元素 完整队列代码 循环队列优先队列是什么&#xff1f;总结 什么是队列&#xff1f; 当我们在浏览器中打开新标签…

【1483. 树节点的第 K 个祖先】

来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 描述&#xff1a; 给你一棵树&#xff0c;树上有 n 个节点&#xff0c;按从 0 到 n-1 编号。树以父节点数组的形式给出&#xff0c;其中 parent[i] 是节点 i 的父节点。树的根节点是编号为 0 的节点。 树节点的第 k 个…

pyecharts使用案例二——全国疫情可视化地图开发

代码 import json from pyecharts.charts import Map from pyecharts.options import *f open("./疫情.txt", "r", encoding"UTF-8") data f.read()f.close()# 取到各省份数据 # 将json字符串转为python字典,反序列化 data_dict json.loads(…

vue3-实战-07-管理后台-属性管理模块开发

目录 1-需求原型分析 2-三级分类全局组件封装 2.1-三级分类组件请求接口和数据类型封装 2.2-组件获取数据渲染数据 3-属性管理列表开发 3.1-请求接口和数据类型封装 3.2-获取数据渲染数据 4-新增编辑属性 4.1-需求原型分析 4.2-新增编辑接口封装和数据类型定义 4.3-…

IDEA在Maven settings.xml失效的情况下反编译代码

在我们日常的工作中有时候会遇到需要调试别人的代码的问题&#xff0c;这个时候别人往往会给你一个jar包&#xff0c;这个包里面的代码都是经过编译的&#xff0c;点击打开函数以后都是后缀是.class的文件&#xff0c;我们调试起来非常不方便&#xff0c;这个时候如果我们想要下…

Vue中如何进行剪贴板操作?

Vue中如何进行剪贴板操作&#xff1f; 在Web应用程序中&#xff0c;剪贴板&#xff08;Clipboard&#xff09;操作是非常常见的操作之一。Vue.js是一款流行的JavaScript框架&#xff0c;它提供了一些有用的工具来处理DOM元素和用户界面。本文将介绍如何在Vue.js中使用剪贴板操…