motor de plantillas (tecnología de la página) --- thymeleaf

10.2.1. Para construir el Medio Ambiente

archivo 10.2.1.1.pom

<?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.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.wthink</groupId>
    <artifactId>day706</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>day706</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-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- thymeleaf  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>2.2.4.RELEASE</version>
        </dependency>
    </dependencies>

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

</project>

10.2.1.2.Application.properties

# thymeleaf
#开发配置为false,避免修改模板还要重启服务器
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.content-type=text/html
#前缀
spring.thymeleaf.prefix=classpath:/templates/
#后缀
spring.thymeleaf.suffix=.html

Código 10.2.1.3.Controller

package com.bwie.springbootdemo12.controller;

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

/**
 * @描述:
 * @作者:zhangyuyang
 * @日期:2020/3/24 15:43
 */
@Controller
public class UserController {

    @RequestMapping("/toIndex")
    public String toIndex(Model model){
        model.addAttribute("name","1712ab");
        return "show";
    }
}

10.2.1.4. Página

<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Show User</title>
</head>
<body>
<table>
        姓名: <p th:text="${name}"> 姓名</p>


</table>
</body>
</html>

10.2.2. Etiqueta

• th: acción definir la ruta del controlador de servidor.
• th: cada 1, escudo lenguaje anillo - frase.
• TE: campos de formulario campo obligatorio.
• th: href define hipervínculos.
• th: sentencia ID ID de la etiqueta div, similar a la propiedad de las etiquetas HTML.
• th: si la declaración condicional.
• th: incluyen ficha Diseño, introducido para reemplazar el contenido del archivo.
• th: Empresa agment ficha Diseño, definir un fragmento de código, referencia conveniente en otro lugar.
• th: objeto de sustitución objeto.
• th: direcciones categoría de imagen src introducido.
• th: texto de la pantalla de texto.
• th: asignación de propiedad de valor.

ciclo 10.2.2.1.th:each

<table>
        <thead>
            <tr>
                <th>序号</th>
                <th>用户名</th>
                <th>密码</th>
                <th>用户昵称</th>
            </tr>
            <tr th:each="user:${userlist}">
                <td th:text="${user.id}"></td>
                <td th:text="${user.username}"></td>
                <td th:text="${user.password}"></td>
                <td th:text="${user.petname}"></td>
            </tr>
        </thead>
  </table>

10.2.2.2. @ Etiqueta

<a th:href="@{/product/comments(prodId=${prod.id},prodId2=${prod.id})}" >删除</a>

相当于
<a href="/sbe/product/comments?prodId=2&prodId2=2">查看</a>
Publicado 14 artículos originales · ganado elogios 4 · Vistas 249

Supongo que te gusta

Origin blog.csdn.net/Red_rose9/article/details/105083442
Recomendado
Clasificación