zoukankan      html  css  js  c++  java
  • SpringBoot集成Thymeleaf前端模版

    1、在application.properties配置文件中添加 thymeleaf 的配置信息

    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/test
    spring.datasource.username=root
    spring.datasource.password=root
    
    spring.thymeleaf.mode=HTML5
    spring.thymeleaf.encoding=UTF-8
    spring.thymeleaf.content-type=text/html
    spring.thymeleaf.cache=false

    2、在pom.xml中引入thymeleaf 的jar包

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    3、创建PageController并添加index方法

    package com.cppdy.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class PageController {
        
        @RequestMapping("index")
        public String index(Model model) {
            model.addAttribute("name","吹泡泡的魚");
            return "index";
        }
    
    }

    4、在src/main/resources下创建templates(默认访问此文件下的html),并创建index.html

       在src/main/resources下创建static(默认访问此文件夹下的静态文件),在static文件夹创建images文件夹,并放入一张图片

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8"/>
    <title>SpringBoot</title>
    </head>
    <body>
        Welcome to cppdy
        <p th:text="${name}"></p>
        <img alt="吹泡泡的魚" th:src="@{/images/logo.jpg}"/>
        <br/>
        <input th:value="${name}"/>
    </body>
    </html>

    注:@表示当前项目路径,static文件夹是系统默认加载的静态文件路径

  • 相关阅读:
    SQL应用初级指南
    XML 文档的基本操作
    SQL中单引号的转义
    C# (输入输出流)
    C# 文件与目录的基本操作(System.IO)
    数据库对象命名
    .Net 中的反射(反射特性) Part.3 (转载)
    C# 中的委托和事件(详解)
    SQL Server TransactSQL 编程
    Brush 色谱
  • 原文地址:https://www.cnblogs.com/jiefu/p/10023846.html
Copyright © 2011-2022 走看看