Spring Boot 教程:Thymeleaf
发布日期:2021-05-14 00:52:26 浏览次数:24 分类:博客文章

本文共 5544 字,大约阅读时间需要 18 分钟。

������������������������
    Thymeleaf ��������������� Java ��������������������������������������������������� web ������������������ web ������������  XHTML/HTML5 ������������������������������������������������������������ Thymeleaf ���������

Thymeleaf ������

   Thymeleaf ��������������������������������������� XML ������������������������ 6 ���������������������
  • XML
  • ������ XML
  • XHTML
  • ������ XHTML
  • HTML5
  • ������ HTML5
   ������������ HTML5 ������������������������������������������ XML ��������������� HTML5 ��������������� web ������������ HTML5 ������������������������������������

Web ������

   ��������������� Thymeleaf ��������� Spring Boot ��������� web ������������������������������������
   ������������������������������ @Controller ��������������������������� URI ��� HTML ���������
1 package com.tutorialspoint.demo.controller; 2   3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5   6 @Controller 7 public class WebController { 8    @RequestMapping(value = "/index") 9    public String index() {10       return "index";11    }12 }
   ��������������������������� URI ��� /index��������������������� index.html ������������������index.html ������������������ templates ������������������������ JS ��� CSS ������������������ classpath ������������ static ������������������������������������ CSS ������������������������
   ������������������������������������������������������������ CSS ��������������������� styles.css���
1 h4 {2    color: red;3 }
   index.html ������������������������
1  2  3     4       
5
6 Spring Boot Application 7 8 9

Welcome to Thymeleaf Spring Boot web application

10 11
   ���������������������������������������
   ������������������������������������������������������������ Spring Boot Starter Thymeleaf ���������
   Maven ������������������������������������ pom.xml ���������
1 
2
org.springframework.boot
3
spring-boot-starter-thymeleaf
4
   Gradle ��������������� build.gradle ������������������������������
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
   ��� Spring Boot ������������������������������
1 package com.tutorialspoint.demo; 2   3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5   6 @SpringBootApplication 7 public class DemoApplication { 8    public static void main(String[] args) { 9       SpringApplication.run(DemoApplication.class, args);10    }11 }
   Maven ��� pom.xml ���������������
1 
2
6 7
4.0.0
8
com.tutorialspoint
9
demo
10
0.0.1-SNAPSHOT
11
jar
12
demo
13
Demo project for Spring Boot
14 15
16
org.springframework.boot
17
spring-boot-starter-parent
18
1.5.8.RELEASE
19
20
21 22
23
UTF-8
24
UTF-8
25
1.8
26
27 28
29
30
org.springframework.boot
31
spring-boot-starter-web
32
33 34
35
org.springframework.boot
36
spring-boot-starter-test
37
test
38
39 40
41
org.springframework.boot
42
spring-boot-starter-thymeleaf
43
44
45 46
47
48
49
org.springframework.boot
50
spring-boot-maven-plugin
51
52
53
54 55
   Gradle ��� build.gradle ���������������
1 buildscript { 2    ext { 3       springBootVersion = '1.5.8.RELEASE' 4    } 5    repositories { 6       mavenCentral() 7    } 8    dependencies { 9       classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")10    }11 }12  13 apply plugin: 'java'14 apply plugin: 'eclipse'15 apply plugin: 'org.springframework.boot'16  17 group = 'com.tutorialspoint'18 version = '0.0.1-SNAPSHOT'19 sourceCompatibility = 1.820  21 repositories {22    mavenCentral()23 }24 dependencies {25    compile('org.springframework.boot:spring-boot-starter-web')26    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'27    testCompile('org.springframework.boot:spring-boot-starter-test')28 }
   ��������������������� Maven ��� Gradle ��������������������� executable JAR ��������������� Spring Boot ������������
   Maven ���������������
mvn clean install
   ��� ���BUILD SUCCESS��� ��������������������� target ��������������� JAR ���������
   Gradle ���������������������������
gradle clean build
   ��� ���BUILD SUCCESSFUL��� ��������������������� build/libs ��������������� JAR ���������
   ������������������������ JAR ���������
java ���jar 
   ������������������ Tomcat 8080 ���������������������������������
   ��������������������������� URL������������������������������������������
 
 
上一篇:Spring Boot 教程:消费 Rest Web 服务
下一篇:Spring Boot 教程:服务组件

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月27日 04时39分51秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章