跟我学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方法注入和构造器注入两种方式.另外,当一个类包含多个构造函数带的参数相同,它总是会造成构造函数注入参数类型歧义的问题 ...
随机推荐
- 如何从Windows中删除Node.js
如何从Windows中删除Node.js: 1.从卸载程序卸载程序和功能. 2.重新启动(或者您可能会从任务管理器中杀死所有与节点相关的进程). 3.寻找这些文件夹并删除它们(及其内容)(如果还有). ...
- GreaseMonkey开发(一):第一个自定义插件Hello GreaseMonkey!
GreaseMonkey最好在火狐浏览器上使用,下载好GreaseMonkey,重启浏览器右上角会出现一只小猴子. 新建一个脚本. 确定,填入代码保存. // ==UserScript== // @n ...
- oracle学习--循环语句
oracle学习--循环语句 loop循环: create or replace procedure pro_test_loop is i number; begin i:=0; loop i:=i ...
- 【OpenGL】第一个窗口
包含头文件: #include <GL/glew.h> // GLFW #include <GLFW/glfw3.h> 初始化与配置GLFW: glfwInit(); //初始 ...
- 【scrapy】关于爬取的内容是Unicode编码
自己练习爬取拉钩网信息的时候爬取的信息如下: {'jobClass': [u'\u9500\u552e\u52a9\u7406'], 'jobUrl': u'https://www.lagou.com ...
- 笔记-Python中逗号的作用
1.用,去掉额外的换行符
- as3.0用了视频组件,导致视频打开后就全屏,加一下代码就行
myFlv.fullScreenTakeOver = false; fullScreenTakeOver : Boolean 舞台进入全屏模式时,FLVPlayback 组件位于所有内容的顶部并占据整 ...
- 第三章 列表(a)接口与实现
- undefined reference to symbol' pthread_create@@GLIBC_2.2.5'
我在ubuntu16.04上迁移工程,遇到了这个错误. pthread库不是Linux系统默认的库,链接时需要添加-pthread参数. 这里注意是链接那一步添加-pthread,而不是编译选项.
- UmBasketella
UmBasketella http://poj.org/problem?id=3737 Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...