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开发的更多相关文章

  1. Solon详解(三)- Solon的web开发

    Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...

  2. Springboot mini - Solon详解(三)- Solon的web开发

    Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...

  3. 【Spring Boot学习之二】WEB开发

    环境 Java1.8 Spring Boot 1.3.2 一.静态资源访问 动静分离:动态服务和前台页面图片分开,静态资源可以使用CDN加速;Spring Boot默认提供静态资源目录位置需置于cla ...

  4. Spring Boot 系列(五)web开发-Thymeleaf、FreeMarker模板引擎

    前面几篇介绍了返回json数据提供良好的RESTful api,下面我们介绍如何把处理完的数据渲染到页面上. Spring Boot 使用模板引擎 Spring Boot 推荐使用Thymeleaf. ...

  5. Spring Boot第五弹,WEB开发初了解~

    持续原创输出,点击上方蓝字关注我吧 目录 前言 Spring Boot 版本 前提条件(必须注意) 添加依赖 第一个接口开发 如何自定义tomcat的端口? 如何自定义项目路径? JSON格式化 日期 ...

  6. spring学习(三) ———— spring事务操作

    前面一篇博文讲解了什么是AOP.学会了写AOP的实现,但是并没有实际运用起来,这一篇博文就算是对AOP技术应用的进阶把,重点是事务的处理. --wh 一.jdbcTemplate 什么是JdbcTem ...

  7. Spring+Maven+Dubbo+MyBatis+Linner+Handlebars—Web开发环境搭建

    本文主要分三部分,分别是:后台核心业务逻辑.桥梁辅助控制和前台显示页面. 本Web开发环境综合了多种工具,包括Maven包管理与编译工具.Dubbo分布式服务框架.MyBatis数据持久化工具.Lin ...

  8. Spring Boot 系列(六)web开发-Spring Boot 热部署

    Spring Boot 热部署 实际开发中,修改某个页面数据或逻辑功能都需要重启应用.这无形中降低了开发效率,所以使用热部署是十分必要的. 什么是热部署? 应用启动后会把编译好的Class文件加载的虚 ...

  9. 玩转Spring MVC(三)----spring基本配置文件

    这篇文章总结一下spring mvc的基本配置,首先贴一张我的项目的目录截图,有一些多余的文件,大家不必在意: 用到的一些jar包在这:<a>http://download.csdn.ne ...

  10. Spring重温(三)--Spring依赖注入(DI)

    前言:在Spring框架中,DI(依赖注入)是用来定义对象彼此间的依赖,主要有set方法注入和构造器注入两种方式.另外,当一个类包含多个构造函数带的参数相同,它总是会造成构造函数注入参数类型歧义的问题 ...

随机推荐

  1. 预览InputFile

    [预览InputFile] 通过input的files属性,可以取到选择的File对象,通过FileReader可以将File对象读取出来. <body> <input type=& ...

  2. 分享一个 Java String split 快速分割的方法

    java中string.split() 方法比较强大,但是split()方法采用正则表达式,速度相对会慢一点, 其实大多数场景下并不需要使用正则表达式,下面分享一个不使用正则表达式分隔字符串的方法. ...

  3. 以字符串形式获取excel单元格中的内容

    public static String getCellValue(XSSFCell cell) { if (cell == null) { return ""; } switch ...

  4. springboot jpa sql查询与传值

    public interface ARepository extends PagingAndSortingRepository<A, APK>, JpaSpecificationExecu ...

  5. hibernate中调用query.list()而出现的黄色警告线

    使用hibernate的时候会用到hql语句查询数据库, 那就一定会用到query.list();这个方法, 那就一定会出现一个长长的黄色的警告线, 不管你想尽什么办法, 总是存在, 虽然说这个黄色的 ...

  6. redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, but seems to be not monitored.

    在使用Redis的哨兵Sentinel配置时,报错如下: redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, ...

  7. hbase 定时备份

    #!/bin/bash#su - hdfs <<EOFdata1=`date "+%Y%m%d%H%M%S"`data2="/user/news/hbase_ ...

  8. TZOJ 2588 Bad Grass(DFS)

    描述 Bessie was munching on tender shoots of grass and, as cows do, contemplating the state of the uni ...

  9. echarts中间有字饼图Demo2

    echarts链接:http://gallery.echartsjs.com/editor.html?c=xHy2vIPzLQ 完整代码: option = { backgroundColor: 'b ...

  10. AngularJS——第9章 模块加载

    第9章 模块加载 AngularJS模块可以在被加载和执行之前对其自身进行配置.我们可以在应用的加载阶段配置不同的逻辑. [AngularJS执行流程] 启动阶段(startup) 开始 --> ...