• SpringBoot入门14(springboot配置thymeleaf使用YML)


    一 pom.xml

    <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 http://maven.apache.org/maven-v4_0_0.xsd">
     
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.fs</groupId>
      <artifactId>springboot_thymeleaf_9_1</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>springboot_thymeleaf_9_1 Maven Webapp</name>
      <url>http://maven.apache.org</url>
     
     
     
        <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>1.5.3.RELEASE</version>
        </parent>
     
        <properties>
          <spring-boot-version>1.5.3.RELEASE</spring-boot-version>
          <junit-version>4.12</junit-version>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <java.version>1.7</java.version>
        </properties>
     
     
        <dependencies>
          <!-- Compile -->
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
          </dependency>
     
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
          </dependency>
     
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
          </dependency>
     
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
     
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
          </dependency>
     
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
          </dependency>
        </dependencies>
     
      <build>
        <finalName>springboot_thymeleaf_9_1</finalName>
     
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
     
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
     
        </plugins>
      </build>
    </project>
    

    二、SampleWebThymeleaf3Application.java

    package com.fs;
     
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
     
    @SpringBootApplication
    public class SampleWebThymeleaf3Application {
     
     
    	public static void main(String[] args) throws Exception {
    		SpringApplication.run(SampleWebThymeleaf3Application.class, args);
    	}
     
    }
    

    三、ThymeleafController.java

    package com.fs.controller;
     
    import java.util.Map;
     
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
     
    @Controller
    @RequestMapping("/")
    public class ThymeleafController {
    	
    	@RequestMapping("/index")
    	public String index(Map<String, Object> map){
    		map.put("user", "Tyrone");
    		return "index";
    	}
    	
    }
    

    四、application.yml

    spring:
      thymeleaf:
        cache: false
        prefix: classpath:/templates/
        suffix: .html
        encoding: UTF-8
        content-type: text/html
        mode: HTML5
    

    五、index.html

    <!DOCTYPE html>
    <html  xmlns:th="http://www.thymeleaf.org">
    <head>
    <meta charset="UTF-8" />
    <title>Insert title here</title>
    </head>
    <body>
    	<p>Hello!<span th:text="${user}"></span>!<br />welcom to Thymeleaf's world</p>
    </body>
    </html>
    
  • 相关阅读:
    爬取笔趣阁小说(一念永恒)
    爬虫requests爬去网页乱码问题
    requests bs4 datetime re json
    添加背景音乐。c
    strip()
    爬虫学习中遇到的问题
    super的用法(带了解)
    user-agent
    输入n个字符串,用空格隔开。这些字符串中有重复出现的。现在统计每个字符串出现的次数,并找出出现次数最多的字符串。
    字节跳动小程序的一些坑
  • 原文地址:https://www.cnblogs.com/powerbear/p/15996521.html
Copyright © 2020-2023  润新知