springBoot 随笔(二)
此文为springBoot 结合 thymeleaf ,解析后台接口数据展示到html页面
基于 springBoot(一)工程。
1/ 引用 thymeleaf 组件依赖
<!-- dependencies 节点下新增-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2/ 新建页面文件存放路径,存放html
src/main/resources/templates
3/ 更新application.properties配置文件,新增thymeleaf 配置文件
#thymelea配置 资源文件目录
spring.thymeleaf.prefix=classpath:/templates/
#后缀
spring.thymeleaf.suffix=.html
#类型
spring.thymeleaf.mode=HTML5
#编码
spring.thymeleaf.encoding=UTF-8
#热部署文件,页面不产生缓存,及时更新
spring.thymeleaf.cache=false
4/新增数据接口
package com.hux.stu.dydatasorce.controller; import java.util.ArrayList;
import java.util.List; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; @RestController
public class ThymeleafDataController { @RequestMapping("page")
public ModelAndView showPage(Model mode) {
List list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
//返回视图以及数据, 根据配置文件 读取资源目录下index.html 文件
return new ModelAndView("index", "list",list); }
}
5/新增页面 index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" /> <!-- 自动生成的文件,该节点没有结束/ ,不添加会报错 -->
<title>Insert title here</title>
</head>
<body> <table>
<tr><td>读取的数据</td></tr>
<tr th:if="${list.size()} eq 0">
<td colspan="3">无数据</td>
</tr>
<!-- 读取数据 -->
<tr th:each="info : ${list}">
<td th:text="${info}"></td>
</tr> </table>
</body>
</html>
6/ main方法运行,访问页面,http://127.0.0.1:8081/page 查看展示数据,展示abcde列表
springBoot 随笔(二)的更多相关文章
- SpringBoot开发二十-Redis入门以及Spring整合Redis
安装 Redis,熟悉 Redis 的命令以及整合Redis,在Spring 中使用Redis. 代码实现 Redis 内置了 16 个库,索引是 0-15 ,默认选择第 0 个 Redis 的常用命 ...
- springboot 入门二- 读取配置信息一
在上篇入门中简单介绍下springboot启动使用了大量的默认配置,在实际开发过程中,经常需要启动多个服务,那端口如何手动修改呢? 此篇就是简单介绍相关的配置文件信息. Spring Boot允许外部 ...
- SpringBoot(二)Web整合开发
Spring Boot (二):Web 综合开发 本篇文章接着上篇内容继续为大家介绍spring boot的其它特性(有些未必是spring boot体系桟的功能,但是是spring特别推荐的一些开源 ...
- SpringBoot学习(二)-->Spring的Java配置方式
二.Spring的Java配置方式 Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 1.@Configuration 和 @Bean Spring的Java配置方式是通过 @ ...
- springboot系列二、springboot项目搭建
一.官网快速构建 1.maven构建项目 1.访问http://start.spring.io/ 2.选择构建工具Maven Project.Spring Boot版本2.1.1以及一些工程基本信息, ...
- Alpha冲刺随笔二:第二天
课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(十天冲刺) 团队名称:葫芦娃队 作业目标:在十天冲刺里对每天的任务进行总结. 随笔汇总:https://www.cnblogs ...
- SpringBoot系列二:搭建自己的第一个SpringBoot程序
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 一.根据官网手工搭建(http://projects.spring.io/spring-boot/#quick-start) 1 ...
- SpringBoot入门 (二) 属性文件读取
在上一篇中介绍了在idea中创建springboot工程及使用web工程输出“helloworld”到前端页面,本文学习在springboot工程中读取属性文件中的属性值. 一 自定义属性 在appl ...
- SpringBoot实战(二)之计划任务
计划任务这个对于Java开发者们,应该不陌生了,非常常用又非常常见.比如jdk自带的Timer 实现例子如下: class MyTask extends TimerTask{ @Override pu ...
随机推荐
- 2018-2019-2 20165335 《网络对抗技术》 Exp6 信息搜集与漏洞扫描
1.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 2.实践内容 (1)各种搜索技巧的应用 (2)DNS IP注册信息的查询 (3)基本的扫描技术:主机发现.端口扫描.OS及服务版本探测.具 ...
- 手机APP应用外网访问本地WEB应用
手机APP应用外网访问本地WEB应用 本地安装了WEB服务端,手机APP应用只能在局域网内访问本地WEB,怎样使手机APP应用从公网也能访问本地WEB? 本文将介绍具体的实现步骤. 1. 准备工作 1 ...
- linux 常用命令 和 nginx(反响代理、负载均衡)安装和配置
(1)linux常用命令 [1]在光标前输入内容:i [2]删除输入方式下所输入的文本:Ctrl+u [3]文件保存退出:wq [4]文件不保存退出:q [5]文件强制退出:q! [6]常规删除文件 ...
- 【js】版本号对比处理方案
今天在处理一个bug问题,适配客户端版本:若版本号未达到,则不可运行该功能,若达到则可运行. 版本号规则如下:(一般统一为2个点,其他的是数字,版本号从高位到低位,首位越大则越大,首位相同则对比下一位 ...
- spring-petclinic性能调优实战(转)
1.spring-petclinic介绍 spring-petclinic是spring官方做的一个宠物商店,结合了spring和其他一些框架的最佳实践. 架构如下: 1)前端 Thymeleaf做H ...
- TCP/IP学习
1.TCP/IP网络包括两部分 ①传输协议 ②网络协议
- L1,L2正则化代码
# L1正则 import numpy as np from sklearn.linear_model import Lasso from sklearn.linear_model import SG ...
- UVA11020 Efficient Solutions
思路 先判断一个点能不能插入,能插入的话删除所有因为它而没有优势的点 注意 写 S.erase(it); it++; 会RE 要写 S.erase(it++); 代码 #include <cst ...
- html2canvas文字重叠(手机端)
发现情况: 1.设置文字居中,文字自动换行后文字有重叠 text-align: center; 解决办法: text-align: left; text-align: justify;等 2.使用 ...
- Asp.net 按钮幕布遮盖效果实现方式
Asp.net button按钮点击后想要实现幕布效果来等待服务器端执行完成,这种需求虽说看起来很简单,但真实做起来并不是那么简单,涉及了很多细节点,而对于深入理解asp.net button生命周期 ...