笔记61 Spring Boot快速入门(一)
IDEA+Spring Boot快速搭建
一、IDEA创建项目
略
项目创建成功后在resources包下,属性文件application.properties中,把数据库连接属性加上,同时可以设置服务端口。
application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/sh
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#页面热加载
spring.thymeleaf.cache = false
#端口
server.port=8888
二、新建控制器
com.example.demo下创建包Controller用来存放控制器
IndexController.java (显示当前时间)
package com.example.demo.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import java.text.DateFormat;
import java.util.Date; @Controller
public class IndexController {
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("time",DateFormat.getDateTimeInstance().format(new Date()));
return "hello";
}
}
三、新建视图html
1.在resources下新建static包,用来存放一些静态资源:css、js、img等。
test.css
body{
color: red;
}
2.在resources下新建templates包,用来存放视图。
在这里使用thymeleaf来显示后台传过来的数据。thymeleaf 跟 JSP 一样,就是运行之后,就得到纯 HTML了。 区别在与,不运行之前, thymeleaf 也是 纯 html ...所以 thymeleaf 不需要 服务端的支持,就能够被以 html 的方式打开,这样就方便前端人员独立设计与调试, jsp 就不行了, 不启动服务器 jsp 都没法运行出结果来。
<1>声明当前文件是 thymeleaf, 里面可以用th开头的属性
<html xmlns:th="http://www.thymeleaf.org">
<2>把 time 的值显示在当前 h2里,用的是th开头的属性: th:text, 而取值用的是 "${time}" 这种写法叫做 ognl,就是跟EL表达式一样吧。 这样取出来放进h2里,从而替换到原来h2标签里的 4个字符 "name" .
<h2 th:text="'Time:'+${time}">time</h2>
hello.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="test.css" type="text/css"/>
</head>
<body>
<h1>Hello Spring Boot</h1>
<h2 th:text="'Time:'+${time}">time</h2>
</body>
</html>
四、运行结果

笔记61 Spring Boot快速入门(一)的更多相关文章
- 笔记65 Spring Boot快速入门(五)
SpringBoot+JPA 一.什么是JPA? JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期 ...
- 笔记63 Spring Boot快速入门(三)
SpringBoot中使用JSP Springboot的默认视图支持是Thymeleaf,但是Thymeleaf还没开始学,熟悉的还是jsp,所以要让Springboot支持 jsp. 一.在pom. ...
- 笔记70 Spring Boot快速入门(八)(重要)
上传文件 一.方式一 1.上传页面 upLoadPage.html <!DOCTYPE html> <html lang="en"> <head> ...
- 笔记64 Spring Boot快速入门(四)
SpringBoot中错误处理.端口设置和上下文路径以及配置切换 一.错误处理 假设在访问首页的时候会出现一些错误,然后将这些错误当作异常抛出,反馈给用户. 1.修改IndexController.j ...
- 笔记62 Spring Boot快速入门(二)
SpringBoot部署 一.jar方式 1.首先安装maven. <1>下载最新的maven版本:https://maven.apache.org/download.cgi <2& ...
- 笔记67 Spring Boot快速入门(七)
SpringBoot+RESTful+JSON 一.RESTful架构 REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. ...
- 笔记66 Spring Boot快速入门(六)
SpringBoot中使用Mybatis 一.注解方式 1.创建映射文件CategoryMapper.java 使用注解@Mapper 表示这是一个Mybatis Mapper接口.使用@Select ...
- Spring Boot 快速入门
Spring Boot 快速入门 http://blog.csdn.net/xiaoyu411502/article/details/47864969 今天给大家介绍一下Spring Boot MVC ...
- Spring Boot快速入门(二):http请求
原文地址:https://lierabbit.cn/articles/4 一.准备 postman:一个接口测试工具 创建一个新工程 选择web 不会的请看Spring Boot快速入门(一):Hel ...
随机推荐
- linux---postgresql的安装和配置
postgresql的安装:源码安装(推荐):http://my.oschina.net/hippora/blog/375292 1.tar -xjvf postgresql-9.3.4.tar.bz ...
- SurfaceView的基本使用(转)
转自:https://www.cnblogs.com/zhangyingai/p/7087371.html SurfaceView的基本使用 一.引入: Android提供了View来进行绘图处理 ...
- zabbix 基于sendmail发送邮件相关问题
先看一下脚本 #!/bin/bash to=$ subject=$ body=$ @qq.com smtp=smtp.qq.com passwd=xxxxxxxxx echo `date " ...
- JavaSE---main方法解读
1.概述 1.1 java程序入口:main方法 public static void main(String[] args){} a,public:java类由JVM调用,为了让JVM自由调用mai ...
- Nacos 1.1.4 发布,业界率先支持 Istio MCP 协议
Nacos是阿里巴巴开源的服务发现与配置管理项目,本次发布的1.1.4版本,主要带来的是与Istio的对接功能,使用的是Istio最新的MCP协议.本文将介绍包括这个功能在内的新版本发布的功能. 升级 ...
- ofbiz保存jsp页面数据
1.前台js保存 <script type="text/javascript" src="/ecloud/js/js/jquery.min.js"> ...
- 在不损坏数据的情况下调整分区大小(ext2\ext3\ext4)
现在的时间是2017年5月27日 我想说调整分区大小没那么麻烦,至少我直接将一个ext3格式分区从50G减少到了30G. 步骤如下 1 首先确保那个分区是未挂载的. 2 调整分区大小,但是其实并没有实 ...
- 数组转xls格式的excel文件&数据转csv格式的excle
/** * 数组转xls格式的excel文件 * @param array $data 需要生成excel文件的数组 * @param string $filename 生成的excel文件名 * 示 ...
- AcWing 217. 绿豆蛙的归宿 (概率期望+拓扑排序)打卡
给出一个有向无环的连通图,起点为1,终点为N,每条边都有一个长度. 数据保证从起点出发能够到达图中所有的点,图中所有的点也都能够到达终点. 绿豆蛙从起点出发,走向终点. 到达每一个顶点时,如果有K条离 ...
- ubuntu18.04 点击启动器实现窗口最小化
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'