跟我学Spring Boot(三)Spring Boot 的web开发
1、Web开发中至关重要的一部分,Web开发的核心内容主要包括内嵌Servlet容器和SpringMVC
spring boot 提供了spring-boot-starter-web 为web开发提供支持,spring-boot-starter-web为我们提供了嵌入的tomcat以及spring mvc 的依赖。而web相关的自动配置存储在spring-boot-autoconfigure.jar的org.springframework.boot.autoconfigure.web下。如果还想了解其它相关支持可查阅相关资料,这里不在深入讲解。
2、本节将带领大家开始学习使用Thymeleaf模板
首先先对Thymeleaf模板进行一些简单介绍,Thymeleaf模板是一个java类库,它是一个xml/xhtml/html5的模板引擎,可以作为MVC的Web应用的View层。Spring Boot 提供了大量模板引擎,包括FreeMarker Groovy Thymeleaf Velocity 和Mustache,国为Thymeleaf提供了完美的Spring mvc 的支持,所以我们这里使用Thymeleaf
2.1引入Thymeleaf模板
下面代码是一个基本的Thymeleaf模板页面,在这里我们引入了BootStrap作为样式控制,和jQuery dom操作。
按前面步骤创建一个spring boot项目、目录结构如下:

1、 在template目录下新建index.html页面代码如下:
index.html
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
<link th:src="@{bootstrap/css/bootstrap.min.css}" href="//cdn.bootcss.com/bootstrap/4.0.0-alpha.5/css/bootstrap.css" rel="stylesheet"/>
<script th:src="@{jquery.min.js}" ></script>
</head>
<body>
<span th:text="${single.name}">${single.name}</span>
</body>
</html>
2、新一个model包,再创建一个person类
package com.example.model; /**
* Created by Administrator on 2016-12-16.
*/
public class Person {
private Integer id;
private String name; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
3、DemoApplication代码如下:
package com.example; import com.example.model.Person;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; @Controller //
@SpringBootApplication
public class DemoApplication { //
@RequestMapping("/helloboot")
public String helloBoot(Model model){
Person single=new Person();
single.setId();
single.setName("lvxiaolong");
model.addAttribute("single",single);
return "index";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
4、application.properties
server.port=
启动项目输入:http://localhost/helloboot就可以看到页面输出内容(lvxiaolong)

下载地址:http://download.csdn.net/detail/ttyyadd/9713292
跟我学Spring Boot(三)Spring Boot 的web开发的更多相关文章
- Solon详解(三)- Solon的web开发
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Springboot mini - Solon详解(三)- Solon的web开发
Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...
- 【Spring Boot学习之二】WEB开发
环境 Java1.8 Spring Boot 1.3.2 一.静态资源访问 动静分离:动态服务和前台页面图片分开,静态资源可以使用CDN加速;Spring Boot默认提供静态资源目录位置需置于cla ...
- Spring Boot 系列(五)web开发-Thymeleaf、FreeMarker模板引擎
前面几篇介绍了返回json数据提供良好的RESTful api,下面我们介绍如何把处理完的数据渲染到页面上. Spring Boot 使用模板引擎 Spring Boot 推荐使用Thymeleaf. ...
- Spring Boot第五弹,WEB开发初了解~
持续原创输出,点击上方蓝字关注我吧 目录 前言 Spring Boot 版本 前提条件(必须注意) 添加依赖 第一个接口开发 如何自定义tomcat的端口? 如何自定义项目路径? JSON格式化 日期 ...
- spring学习(三) ———— spring事务操作
前面一篇博文讲解了什么是AOP.学会了写AOP的实现,但是并没有实际运用起来,这一篇博文就算是对AOP技术应用的进阶把,重点是事务的处理. --wh 一.jdbcTemplate 什么是JdbcTem ...
- Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建
本文主要分三部分,分别是:后台核心业务逻辑.桥梁辅助控制和前台显示页面. 本Web开发环境综合了多种工具,包括Maven包管理与编译工具.Dubbo分布式服务框架.MyBatis数据持久化工具.Lin ...
- Spring Boot 系列(六)web开发-Spring Boot 热部署
Spring Boot 热部署 实际开发中,修改某个页面数据或逻辑功能都需要重启应用.这无形中降低了开发效率,所以使用热部署是十分必要的. 什么是热部署? 应用启动后会把编译好的Class文件加载的虚 ...
- 玩转Spring MVC(三)----spring基本配置文件
这篇文章总结一下spring mvc的基本配置,首先贴一张我的项目的目录截图,有一些多余的文件,大家不必在意: 用到的一些jar包在这:<a>http://download.csdn.ne ...
- Spring重温(三)--Spring依赖注入(DI)
前言:在Spring框架中,DI(依赖注入)是用来定义对象彼此间的依赖,主要有set方法注入和构造器注入两种方式.另外,当一个类包含多个构造函数带的参数相同,它总是会造成构造函数注入参数类型歧义的问题 ...
随机推荐
- 安装scrapy框架
前提安装好python.setuptools. 1.安装Python 安装完了记得配置环境,将python目录和python目录下的Scripts目录添加到系统环境变量的Path里.在cmd中输入py ...
- Spring知识结构
课程目标: 1. 回顾 * 传统的开发模式 * Struts与Hibernate可以做什么事? ...
- DataGridView中DataGridViewComboBoxColumn的一些相关应用(一)让其值改变时触发事件-转
转自 https://maodaili.de/mao.php?u=a%2FMrbEvUE8PnCuc7FrhJi0Rqd3kmOBHPZUbcJ1c2hbJUK0RYWpAf4lhIOddItP%2 ...
- STL::unordered_map/unordered_multimap
unordered_map: 和 unorder_set 相似,该容器内部同样根据 hash value 把键值对存放到相应的 bucket(slot)中,根据单个 key 来访问 value 的速度 ...
- Nginx的配置文件nginx.conf配置详解
user nginx nginx; #Nginx用户及组:用户 组.window下不指定 worker_processes 8; #工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. ...
- MAP使用方法集合
一.整理: 看到array,就要想到角标. 看到link,就要想到first,last. 看到hash,就要想到hashCode,equals. 看到tree,就要想到两个接口.Comparable, ...
- vue 登录前做校验this.$router.push(location)
有很多按钮在执行跳转之前,还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转 例如:登录按钮,点击时需要先判断验证码等是否正确,此时
- TOJ 2778 数据结构练习题――分油问题(广搜和哈希)
描述 设有大小不等的三个无刻度的油桶,分别能盛满x,y,z公升油.初始时,第一个油桶盛满油,第二.三个油桶为空,在某一个油桶上分出targ公升油. 输入 输入包含多组测试数据.每组数据包含一行.分别x ...
- swift - 本地通知
1. AppDelegate 注册 class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? fun ...
- 大话listview之设置item监听器无效大坑之一:item设了属性clickable
今天一个listview设置item监听器居然没有作用: 看了半天,怀疑是item设置了这个属性, 于是删了,果然就可以了. 大坑 ...