Spring Boot 学习笔记


 

0. 说明

  从本身的我的独立博客 https://share23.github.io 中迁移与补充css

  原文连接:Spring Boot 学习笔记html

  说明:做为基于大数据的餐饮推荐系统可视化部分的内容,与 基于大数据的餐饮推荐系统总结 一块儿看能加深对总体项目的理解前端

 


 

1. Spring Boot 介绍

  1.1 Spring Boot 是什么 & 能作什么

  Spring Boot 是一个轻量级框架。java

  其设计的目的是用来简化 Spring 应用的初始搭建和开发的过程,使开发者更方便、快捷地开发网站。git

 

  1.2 选择 Spring Boot 的初衷 & 更新记录

  // 2018.4.15github

  由于有个项目须要用一个页面来显示从 HBase 中读取的数据web

  这只是一个想法spring

  未验证其可行性segmentfault

 

  // 2018.4.23springboot

  已验证其可行性

  现已实现从 HBase 中读取的数据而后显示在网页中

  实现将其热部署

 

  //2018.9.11

  完成博文迁移,并修改与补充部份内容

 


 

2. 实例解析

  2.1 需求分析

  须要在 Web 界面动态展现 HBase 中的数据

  HBase 中的数据是会发送变化的,因此项目须要热部署,并对页面动态刷新。

 

  2.2 环境说明

  开发工具: Intellij IDEA

  Java版本: 1.8.0_161

 

  2.3 项目目录结构

├── src
│   ├── main
│   │   ├── java
│   │   │   ├── foodrecommender
│   │   │       ├── controller
│   │   │       │   └── RecController.java
│   │   │       ├── dao
│   │   │       │   └── FoodRecDAO.java
│   │   │       ├── domain
│   │   │       │   └── FoodRec.java
│   │   │       ├── utils
│   │   │       │   └── HBaseUtils.java
│   │   │       │            
│   │   │       └── FoodrecomenderApplication.java
│   │   │
│   │   └── resources
│   │       ├── static
│   │       │   ├── css
│   │       │   └── images
│   │       ├── templates
│   │       │   └── index.html
│   │       └── application.yml 
│   │
│   └── test             
│
├── pom.xml

 


 

3. 学习历程

  3.1 运行第一个 Spring Boot 项目

  根据慕课网上的教程 2小时学会Spring Boot  解锁怎么在 IDEA 新建一个 Spring Boot 项目

  并写一个简易的 Hello Spring Boot 显示在网页中

 

  3.2 Spring Boot 集成 Thymeleaf

  通常都是先在 pom.xml 文件中添加 Thymeleaf 的依赖以下:

<!--Thymeleaf模板-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

  在 templates 目录中新建 index.html

  (PS: 为了显示的效果,我直接放进一个作好布局静态的 html文件)

  采用 ModelAndView 在 RecController.java 中指定 index.html

  进行相关测试,能在页面中看到效果。

 

  3.3 测试是否能从 HBase 中读取数据

  写一个 HBase 操做工具类 HBaseUtils.java

  验证是否能从 HBase 中读取数据

 

  3.4 规范代码结构

  实体类 FoodRec.java

  数据访问层 FoodRecDAO.java

 

  3.5 将从 HBase 中读取的数据显示在前端的 index.html 中

  参考  Spring Boot和Thymeleaf集成  中 ModelAndView 传值的例子以下:

@RequestMapping(method = RequestMethod.GET)
public ModelAndView home(ModelAndView model) {
    model.getModel().put("firstName", "set param firstname in ModelAndView");
    model.getModel().put("lastName", "set param lastname in ModelAndView");
    model.setViewName("RequestParam");
    return model;
}

  参考连接以下:

  1. http://www.javashuo.com/article/p-vtehjyde-hg.html
  2. https://github.com/Terry-Shi/blog/wiki/Spring-Boot-thymeleaf#spring-boot%E5%92%8Cthymeleaf%E9%9B%86%E6%88%90
  3. https://segmentfault.com/a/1190000014352023

 

  3.6 实现热部署

  因为 HBase 中的数据是变化的,因此须要动态更新页面

  而当前的网站是静态的,只是在启动的时候执行了一次

  参考

  springboot集成thymeleaf(不重启刷新html)

  spring-boot 速成(2) devtools之热部署及LiveReload

 

  他教程中最后那步针对的是 MAC 系统

  若是是 Windows 系统能够参考第二个连接中的说明

  步骤为 Keymap -> Other -> Maintenance

  我找到以后发现他的快捷键为 Ctrl + Alt + Shift + /

 

  3.7 验证热部署

  在 HBase 中对数据作相关的覆盖操做,发现网站页面上的数据并无改变

  在手动刷新网页后能获得新的结果

  但这不能知足咱们的需求

  根据实际需求在网上找到这篇文章 网页页面 自动刷新的3种代码

  采用其中最简单的第一种方法,实现了页面的自动刷新

 


 

4. 项目展现

  

 

  


 

5. 项目地址

  待上传

 

 


 

6. 总结

  从 0 开始到获得我想要的效果。

  一个小目标一个小目标的实现,期间经历了屡次可行性验证

  一开始有不少问题,都借助搜索引擎解决了

  参照着 提问的智慧 中的一原则,也向别人请教了一些问题

  大多数都是本身解决的

  记录下整个过程

  这就是我走过的路

相关文章
相关标签/搜索