本篇文章将引导你创建一个简单的Spring Boot web程序示例,涉及到的组件有:嵌入的Tomcat + Thymeleaf 模板引擎,可执行的 JAR 文件包。

开发工具:

1.Spring Boot 1.5.3.RELEASE

2.Spring 4.3.8.RELEASE

3.Thymeleaf 2.1.5.RELEASE

4.Tomcat Embed 8.5.14

5.Maven 3

6.Java 8

1.创建项目

eclipse -- File -- New -- Maven Project

2.项目的目录结构如下所示:

手动创建如下的文件夹及文件

3.项目依赖 pom.xml

spring-boot-starter-thymeleaf 这个依赖包将为你提供一切需要的东西来开发一个  Spring + Thymeleaf 程序

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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.thinkingingis</groupId><artifactId>spring-boot-web-thymeleaf</artifactId><version>0.0.1-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent><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-devtools</artifactId><optional>true</optional></dependency><!-- bootstrap 依赖--><dependency><groupId>org.webjars</groupId><artifactId>bootstrap</artifactId><version>3.3.7</version></dependency></dependencies><build><plugins><!-- macOS 使用如下plugin  这是告诉可执行的jar文件位置,具体情况视你jdk的安装位置而定--><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><configuration><fork>true</fork><executable>/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java</executable></configuration></plugin><!--windows 系统 使用如下plugin  --><!-- <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin>--></plugins></build></project>

显示项目的依赖:在终端输入mvn dependency: tree

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building spring-boot-web-thymeleaf 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ spring-boot-web-thymeleaf ---
[INFO] org.thinkingingis:spring-boot-web-thymeleaf:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.5.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.3.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  +- org.springframework:spring-core:jar:4.3.8.RELEASE:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.5.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.3.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.14:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.14:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.14:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.8:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.8:compile
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.8.RELEASE:compile
[INFO] |  |  |  +- org.springframework:spring-aop:jar:4.3.8.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-beans:jar:4.3.8.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.8.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-expression:jar:4.3.8.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] |  |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] |     \- org.codehaus.groovy:groovy:jar:2.4.10:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.3.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.3.RELEASE:compile
[INFO] \- org.webjars:bootstrap:jar:3.3.7:compile
[INFO]    \- org.webjars:jquery:jar:1.11.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.139 s
[INFO] Finished at: 2017-06-10T14:11:29+08:00
[INFO] Final Memory: 21M/226M
[INFO] ------------------------------------------------------------------------

出现 BUILD SUCCESS  表示成功。

4.Spring Boot

4.1添加@SpringBootApplication注解,运行这个类完成spring boot web程序的启动。

package org.thinkingingis;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBootWebApplication {public static void main(String[] args){SpringApplication.run(SpringBootWebApplication.class, args);}}

4.2 添加controller类 WelcomeController.java

package org.thinkingingis;import java.util.Map;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class WelcomeController {@Value("${welcome.message:test}")private String message = "Hello ThinkingInGIS";@RequestMapping("/")public String welcome(Map<String, Object> model){model.put("message", this.message);return "welcome";}}

5. 添加thymeleaf 资源

5.1将thymeleaf模板文件存放在 src/main/resources/templates/ 下

welcome.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Boot + Thymeleaf Hello World 示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" /></head>
<body><nav class="navbar navbar-inverse"><div class="container"><div class="navbar-header"><a class="navbar-brand" href="#">Spring Boot</a></div><div id="navbar" class="collapse navbar-collapse"><ul class="nav navbar-nav"><li class="active"><a href="#">Home</a></li></ul></div></div></nav><div class="container"><div class="starter-template"><h1 style="color: #4EE2EC">Spring Boot Web Thymeleaf 示例</h1><h2 style="color: #ED594E"><span th:text="'Message: ' + ${message}"></span></h2></div></div><script type="text/javascript" src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script></body>
</html>

5.2 properties文件,放在src/main/resources/ 文件夹下

application.properties

welcome.message: Hello ThinkingInGIS ~ |  \u5FAE\u4FE1\u516C\u4F17\u53F7\uFF1A ThinkingInGIS

6. 启动

6.1进入项目目录下:/Users/gisboy/Documents/workspace/spring-boot-web-thymeleaf

6.2输入  mvn spring-boot:run

$ mvn spring-boot:run.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v1.5.3.RELEASE)

出现 BUILD SUCCESS  表示成功

6.3访问 http://localhost:8080

至此,一个简单的spring boot + thymeleaf 程序 就搭建好了。

(如遇到问题,请留言给作者,以便共同探讨gis知识。thinkingingis@qq.com)

在下开通了一个微信公众号: ThinkingInGIS

欢迎大家关注:)

Spring Boot + Thymeleaf 创建web项目相关推荐

  1. Spring Boot + JSP 创建web项目

    虽然Spring Boot的官网不推荐使用JSPs,但是本篇文章还是带你实现Spring Boot + JSP创建一个简单的web项目.想要用Spring Boot + Thymeleaf实现web项 ...

  2. spring boot新建非web项目(无需依赖)

    spring boot新建非web项目(无需依赖) spring boot集成spring data jpa的时候需要jdk版本为1.8,所以jdk的版本最好设置为1.8 如果新建的项目是以jsp为模 ...

  3. Spring Boot 学习[四] web项目实战训练(增删改查,分页,排序)

    Spring boot非常适合Web应用程序开发.您可以轻松创建自包含的HTTP应用.web服务器采用嵌入式Tomcat,或者Jetty等. 几点说明: Spring boot开发web项目,通常打成 ...

  4. 签到功能设计(含每日签到、固定时段签到、定位并签到模块)-spring Boot版本java web项目,附源码下载地址

    一.签到类型 每日签到:每日开放签到,时间记录为:年.月.日. 固定时段签到:每日固定时段签到,时间记录为:年.月.日.时.分.秒. 核心问题:判断用户签到时间是否在规定的时间段内. 定位并签到:每日 ...

  5. 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面

    贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...

  6. spring创建web项目_使用Spring WS创建合同优先的Web服务

    spring创建web项目 1引言 本文介绍了如何使用来实现和测试SOAP Web服务 Spring Web Services项目 . 本示例将JAXB2用于(取消)编组. 为了开发服务,我将使用合同 ...

  7. Spring boot+Thymeleaf+easyui集成:js创建组件页面报错

    开发工具:Ideal 使用场景:Demo 前提:        环境:Spring boot +Thymeleaf+easyui 引入thymeleaf模板引擎 1 <html lang=&qu ...

  8. 一个强大的开源的基于Spring Boot开发的Web支付系统项目,支持聚合码支付

    一个强大的开源的基于Spring Boot开发的Web支付系统项目,支持聚合码支付.

  9. Spring Boot(二):Web 综合开发

    Spring Boot(二):Web 综合开发 上篇文章介绍了 Spring Boot 初级教程:Spring Boot(一):入门篇,方便大家快速入门.了解实践 Spring Boot 特性:本篇文 ...

最新文章

  1. mf模型 svd++_算法小板报(六)——初探MF(矩阵分解)和FM模型
  2. Android之设置ListView数据显示的动画效果
  3. 学习使用ASP对象和组件
  4. sed模式空间(pattern space)和保持空间(hold space)
  5. C/C++输入输出流
  6. SIGIR2020 | 淘宝提出结合知识图谱与大规模推荐的新框架ATBRG
  7. 从Kubernetes安全地访问AWS服务,告诉你多云场景下如何管理云凭据!
  8. linux 怎么创建接口文件,我们如何在Linux上创建多个虚拟接口?
  9. 比特币挖矿难度上调至23.14T,创历史新高
  10. WCF服务编程 学习笔记(1)
  11. 事务不是与当前连接无关联就是已完成_mysql索引锁事务
  12. 为什么线程池里的方法会执行两次_别以为线程池很简单,来回答下这些问题!...
  13. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_02 递归_5_综合案例_文件搜索...
  14. 生成手写文字图片_如何把手机图片转成PDF文件?这个技巧你一定能学会!
  15. PCI/PCIE相关知识
  16. html银河特效编码,html5 canvas银河星系动画特效
  17. iOS获取当前设备型号等信息总结 包含iPhone7和iPhone7P
  18. 川普撞脸希拉里(基于 OpenCV 的面部特征交换)-1
  19. 用python抠图方便还是ps方便_我会Python之后都不屑用PS了,Python抠图太方便了!...
  20. 天圆地方放样软件_天圆地方放样方法

热门文章

  1. [BZOJ 1012] 最大数maxnumber
  2. ICCV 2017 《Flow-Guided Feature Aggregation for Video Object Detection》论文笔记
  3. AtCoder AGC030E Less Than 3
  4. BZOJ 2959 长跑 (LCT、并查集)
  5. html写三角形,css3怎么写三角形?
  6. oracle 并行提交,如何配置Oracle并行处理(上)
  7. 2019-11-23 Modern Family Scripts (01 “Pilot”)
  8. (12)高斯和均值模糊放到一起
  9. 【docker redis】Could not connect to Redis No route to host
  10. 台湾ML笔记--1.2 formalize the learning probelm