此文为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 随笔(二)的更多相关文章

  1. SpringBoot开发二十-Redis入门以及Spring整合Redis

    安装 Redis,熟悉 Redis 的命令以及整合Redis,在Spring 中使用Redis. 代码实现 Redis 内置了 16 个库,索引是 0-15 ,默认选择第 0 个 Redis 的常用命 ...

  2. springboot 入门二- 读取配置信息一

    在上篇入门中简单介绍下springboot启动使用了大量的默认配置,在实际开发过程中,经常需要启动多个服务,那端口如何手动修改呢? 此篇就是简单介绍相关的配置文件信息. Spring Boot允许外部 ...

  3. SpringBoot(二)Web整合开发

    Spring Boot (二):Web 综合开发 本篇文章接着上篇内容继续为大家介绍spring boot的其它特性(有些未必是spring boot体系桟的功能,但是是spring特别推荐的一些开源 ...

  4. SpringBoot学习(二)-->Spring的Java配置方式

    二.Spring的Java配置方式 Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 1.@Configuration 和 @Bean Spring的Java配置方式是通过 @ ...

  5. springboot系列二、springboot项目搭建

    一.官网快速构建 1.maven构建项目 1.访问http://start.spring.io/ 2.选择构建工具Maven Project.Spring Boot版本2.1.1以及一些工程基本信息, ...

  6. Alpha冲刺随笔二:第二天

    课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(十天冲刺) 团队名称:葫芦娃队 作业目标:在十天冲刺里对每天的任务进行总结. 随笔汇总:https://www.cnblogs ...

  7. SpringBoot系列二:搭建自己的第一个SpringBoot程序

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 一.根据官网手工搭建(http://projects.spring.io/spring-boot/#quick-start) 1 ...

  8. SpringBoot入门 (二) 属性文件读取

    在上一篇中介绍了在idea中创建springboot工程及使用web工程输出“helloworld”到前端页面,本文学习在springboot工程中读取属性文件中的属性值. 一 自定义属性 在appl ...

  9. SpringBoot实战(二)之计划任务

    计划任务这个对于Java开发者们,应该不陌生了,非常常用又非常常见.比如jdk自带的Timer 实现例子如下: class MyTask extends TimerTask{ @Override pu ...

随机推荐

  1. 微信小程序数组对象

    xml:<block wx:for="{{post_key}}" wx:for-item="{{item}}"></block> dat ...

  2. IDEA日常遇到问题汇总

    1. IDEA .gitignore文件不显示在项目栏中 解决方法,setting  >> Editor >> Code Style >> File Type &g ...

  3. 推荐!PlayGround:可视化神经网络

    https://cloud.tencent.com/developer/news/190352 http://playground.tensorflow.org PlayGround是一个在线演示.实 ...

  4. centos6添加mysql服务自启动

    环境: os: centos 6 db:mysql 5.6.40 1.修改/etc/init.d/mysqld文件,默认文件以及存在,该文件内容如下: #!/bin/sh # Copyright Ab ...

  5. [darknet]查看错误结果 sight of wrong

    import os import numpy import cv2 bad_label_file = open("bad_valid.list",'r') names = [] f ...

  6. 2019十大安卓手游折扣平台app排行榜

    2019游戏版号陆续开放,玩家又有许多好游戏可以玩了. 小编就以当前最热门的十个游戏来点评手游折扣平台App排行榜吧! 排名第一的游戏: 少年西游记-新征程 老平台,集成SDK,良心平台,覆盖全网游戏 ...

  7. 中间件详解,Django复习

    day74 2018-05-21 课程安排周一: 中间件 auth模块+分析BBS项目需求(小组讨论把表结构设计出来) 1. 今日内容 中间件:http://www.cnblogs.com/liwen ...

  8. Bootstrap3基础 栅格系统 col-md-push/pull 向左、右的浮动偏移

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  9. ActiveReports 大数据分析报告:2019软件开发者现状

    “C++很不错,PHP是世界上最好的语言,所以我选Java …” 在全球软件开发者群体中,关于最优语言与最优框架的争论从未停止. 本次 ActiveReports 大数据分析报告,将借助权威数据,为您 ...

  10. centos 7安装phantomjs

    centos 7安装phantomjs wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_6 ...