day2 - SpringBoot框架开发技术
主要内容
1. SpringBoot简介
2. 构建springboot工程
3. springboot接口返回json
4. springboot热部署
5. springboot资源属性配置
6. springboot整合模板引擎
7. springboot异常处理
8. springboot整合MyBatis
9. springboot整合redis
10. springboot整合定时任务
11. springboot整合异步任务以及使用场景
12. springboot中如何使用拦截器
1. SpringBoot简介
SpringBoot特点
- 基于spring, 使开发者快速入门,门槛较低
- Springboot可以创建独立运行的应用而不依赖于容器
- 不需要打包成war包,可以放入tomcat直接运行
- 提供maven极简配置,缺点是会引入很多你不需要的包
- 根据项目来依赖,从而配置spring,需要什么配什么
- 提供可视化的相关功能,方便监控,比如性能,应用的健康程度等
- 简化配置,不用再看过多的xml
- 为微服务SpringCloud铺路, SpringBoot可以整合很多各式各样的框架来构建微服务,比如dubbo, thrift等等
2. 构建springboot工程
Reference: https://blog.csdn.net/typa01_kk/article/details/76696618
3. springboot接口返回json
SpringBoot构造并返回一个json对象
package com.firsttry.helloworld.controller;import com.firsttry.helloworld.pojo.IMoocJSONResult;
import com.firsttry.helloworld.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import java.util.Date;//@Controller
@RestController //@RestController = @Controller + @ResponseBody
@RequestMapping("/user")
public class UserController {@RequestMapping("/getUser")/*表示将返回的数据封装成json字符串*///@ResponseBodypublic User getUser(){User u = new User();u.setName("Alisa");u.setAge(21);u.setBirthday(new Date());u.setPassword("111111111");u.setDesc("hello I hope I can be much happier, hahahah");return u;}@RequestMapping("/getUserJson")/*表示将返回的数据封装成json字符串*///@ResponseBodypublic IMoocJSONResult getUserJson(){User u = new User();u.setName("Alisa");u.setAge(21);u.setBirthday(new Date());u.setPassword("111111");u.setDesc("emmmmmm11122222");return IMoocJSONResult.ok(u);}
}
Jackson的基本演绎法
package com.firsttry.helloworld.pojo;import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;import java.util.Date;public class User {private String name;@JsonIgnoreprivate String password;private Integer age;@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss a", locale = "Aus", timezone = "GMT+10")private Date birthday;@JsonInclude(JsonInclude.Include.NON_NULL)private String desc;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public String getDesc() {return desc;}public void setDesc(String desc) {this.desc = desc;}
}
4. springboot热部署
SpringBoot使用devtools进行热部署,不需要重启服务器就可以部署文件
Reference: https://www.jianshu.com/p/0e3efd50e3e3
5. springboot资源属性配置
6. springboot整合模板引擎
1. springBoot整合freemarker
pom.xml
<!--引入freemarker模板依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency>
application.properties
########
#
# freemarker 静态资源配置
#
########
# 设定ftl文件路径
spring.freemarker.template-loader-path=classpath:/templates
# 关闭缓存,即时刷新,上线生产环境需改为true
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl
freemarkerController
package com.firsttry.helloworld.controller;import com.firsttry.helloworld.pojo.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping("ftl")
public class FreemarkerController {@Autowiredprivate Resource resource;@RequestMapping("/index")public String index(ModelMap map){map.addAttribute("resource", resource);return "freemarker/index";}@RequestMapping("center")public String center(){return "freemarker/center/center";}}
2. springBoot整合thymeleaf
pom.xml
<!--引入thymeleaf模板依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>
application.properties
########
#
# thymeleaf 静态资源配置
#
########
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
# 关闭缓存,即时刷新,上线生产环境需要改为true
spring.thymeleaf.cache=false
ThymeleafController
package com.firsttry.helloworld.controller;import com.firsttry.helloworld.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;import java.util.ArrayList;
import java.util.Date;
import java.util.List;@Controller
@RequestMapping("th")
public class ThymeleafController {@RequestMapping("/index")public String index(ModelMap map){map.addAttribute("name", "thymeleaf-imooc");return "thymeleaf/index";}@RequestMapping("center")public String center() {return "thymeleaf/center/center";}@RequestMapping("test")public String test(ModelMap map) {User u = new User();u.setName("manager");u.setAge(10);u.setPassword("123465");u.setBirthday(new Date());u.setDesc("<font color='green'><b>hello imooc</b></font>");map.addAttribute("user", u);User u1 = new User();u1.setAge(19);u1.setName("imooc");u1.setPassword("123456");u1.setBirthday(new Date());User u2 = new User();u2.setAge(17);u2.setName("superadmin");u2.setPassword("123456");u2.setBirthday(new Date());List<User> userList = new ArrayList<User>();userList.add(u);userList.add(u1);userList.add(u2);map.addAttribute("userList", userList);return "thymeleaf/test";}@PostMapping("postform")public String postform(User u) {System.out.println("姓名:" + u.getName());System.out.println("年龄:" + u.getAge());return "redirect:/th/test";}
}
thymeleaf常用标签的使用方法
- 基本使用方式
- 对象引用方式
- 时间类型转换
- text与utext的比较
utext: html代码会解析成对应的css代码 - URL
- 引入静态资源
- 条件判断th:if
- th:unless 与 th:if 的使用
- 循环 th:each
- text 与 utext
- th:switch 与 th:case
7. springboot异常处理
- 页面跳转形式
- ajax形式
- 统一返回异常的形式
8. springboot整合MyBatis
- 使用generatorConfig生成mapper以及pojo
- 实现基于mybatis的CRUD功能
- 整合mybatis-pagehelper实现分页
- 自定义mapper的实现
SpringBoot整合持久层事务(为数据库操作设定事务级别)
- 事务隔离级别:DEFAULT READ_UNCOMMITTED READ_COMMITTED REPEATABLE_READ SERIALIZABLE
-事务的传播行为:REQUIRED SUPPORTS MANDATORY REQUIRES_NEW NOT_SUPPORTED NEVER NESTED
9. springboot整合redis
- pom.xml引入需要的依赖
- 资源文件中对redis进行配置
- 引入redis工具类
10. springboot整合定时任务task
- 使用注解@EbableScheduling开启定时任务,会自动扫描
- 定义@Component作为组件被容器扫描
- 表达式生成地址: https://cron.qqe2.com/
11. springboot整合异步任务以及使用场景
- 使用注解@EnableAsync开启异步,会自动扫描
- 定义@Component @Async作为组件被容器扫描执行
12. springboot中如何使用拦截器
- 使用注解@Configuration配置拦截器
- 继承WebMvcConfigurerAdapter
- 重写addInterceptors添加需要的拦截器地址
本文主要参考源码:https://github.com/leechenxiang/imooc-springboot-starter

喜欢的朋友记得点赞、收藏、关注哦!!!
相关文章:

day2 - SpringBoot框架开发技术
主要内容 1. SpringBoot简介 2. 构建springboot工程 3. springboot接口返回json 4. springboot热部署 5. springboot资源属性配置 6. springboot整合模板引擎 7. springboot异常处理 8. springboot整合MyBatis 9. springboot整合redis 10. springboot整合定时任务 11. springbo…...

Flash-03
1-问题:Flash软件画两个图形,若有部分重合则变为一个整体 解决方法1:两个图形分属于不同的图层 解决方法2:将每个图形都转化为【元件】 问题2:元件是什么? 在 Adobe Flash(现在称为 Adobe Anim…...

新建菜单项的创建之CmpGetValueListFromCache函数分析
第一部分: PCELL_DATA CmpGetValueListFromCache( IN PHHIVE Hive, IN PCACHED_CHILD_LIST ChildList, OUT BOOLEAN *IndexCached, OUT PHCELL_INDEX ValueListToRelease ) 0: kd> dv KeyControlBlock 0xe1…...

【Word2Vec】Skip-gram 的直观理解(深入浅出)
01 什么是skip-gram 一句话来说就是,给定中心词,然后预测其周围的词: 02 模型结构 对于skip-gram来说,输入是一个[1 x V]维的ont-hot向量,其中V为词表大小,值为1的那一项就表示我们的中心词。经过一个[V x…...

在MacOS上打造本地部署的大模型知识库(一)
一、在MacOS上安装Ollama docker run -d -p 3000:8080 --add-hosthost.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main 最后停掉Docker的ollama,就能在webui中加载llama模…...

(21)从strerror到strtok:解码C语言字符函数的“生存指南2”
❤个人主页:折枝寄北的博客 ❤专栏位置:简单入手C语言专栏 目录 前言1. 错误信息报告1.1 strerror 2. 字符操作2.1 字符分类函数2.2 字符转换函数 3. 内存操作函数3.1 memcpy3.2 memmove3.2memset3.3 memcmp 感谢您的阅读 前言 当你写下strcpy(dest, s…...

DeepSeek推出DeepEP:首个开源EP通信库,让MoE模型训练与推理起飞!
今天,DeepSeek 在继 FlashMLA 之后,推出了第二个 OpenSourceWeek 开源项目——DeepEP。 作为首个专为MoE(Mixture-of-Experts)训练与推理设计的开源 EP 通信库,DeepEP 在EP(Expert Parallelism)…...

1.2 Kaggle大白话:Eedi竞赛Transformer框架解决方案02-GPT_4o生成训练集缺失数据
目录 0. 本栏目竞赛汇总表1. 本文主旨2. AI工程架构3. 数据预处理模块3.1 配置数据路径和处理参数3.2 配置API参数3.3 配置输出路径 4. AI并行处理模块4.1 定义LLM客户端类4.2 定义数据处理函数4.3 定义JSON保存函数4.4 定义数据分片函数4.5 定义分片处理函数4.5 定义文件名排序…...

数据结构-顺序表专题
大家好!这里是摆子,今天给大家带来的是C语言数据结构开端-顺序表专题,主要介绍了数据结构和动态顺序表的实现,快来看看吧!记得一键三连哦! 1.数据结构的概念 1.1什么是数据结构? 数据结构是计…...
docker和containerd从TLS harbor拉取镜像
私有镜像仓库配置了自签名证书,https访问,好处是不需要处理免费证书和付费证书带来的证书文件变更,证书文件变更后需要重启服务,自签名证书需要将一套客户端证书存放在/etc/docker/cert.d目录下,或者/etc/containerd/c…...

kafka-关于ISR-概述
一. 什么是ISR ? Kafka 中通常每个分区都有多个副本,其中一个副本被选举为 Leader,其他副本为 Follower。ISR 是指与 Leader 副本保持同步的 Follower 副本集合。ISR 机制的核心是确保数据在多个副本之间的一致性和可靠性,同时在 …...

el-input实现金额输入
需求:想要实现一个输入金额的el-input,限制只能输入数字和一个小数点。失焦数字转千分位,聚焦转为数字,超过最大值,红字提示 效果图 失焦 聚焦 报错效果 // 组件limitDialog <template><el-dialog:visible.s…...
C++11智能指针
一、指针管理的困境 资源释放了,但指针没有置空(野指针、指针悬挂、踩内存) 没有释放资源,产生内存泄漏问题;重复释放资源,引发coredump 二、智能指针...

安装Git(小白也会装)
一、官网下载:Git 1.依次点击(红框) 不要安装在C盘了,要炸了!!! 后面都 使用默认就好了,不用改,直接Next! 直到这里,选第一个 这两种选项的区别如…...

驭势科技9周年:怀揣理想,踏浪前行
2025年的2月,驭势科技迎来9岁生日。位于国内外不同工作地的Uiseeker齐聚线上线下,共同庆祝驭势走过的璀璨九年。 驭势科技联合创始人、董事长兼CEO吴甘沙现场分享了驭势9年的奔赴之路,每一段故事都包含着坚持与拼搏。 左右滑动查看更多 Part.…...

一款在手机上制作电子表格
今天给大家分享一款在手机上制作电子表格的,免费好用的Exce1表格软件,让工作变得更加简单。 1 软件介绍 Exce1是一款手机制作表格的办公软件,您可以使用手机exce1在线制作表格、工资表、编辑xlsx和xls表格文件等,还可以学习使用…...
Python解决“比赛配对”问题
Python解决“比赛配对”问题 问题描述测试样例解决思路代码 问题描述 小R正在组织一个比赛,比赛中有 n 支队伍参赛。比赛遵循以下独特的赛制: 如果当前队伍数为 偶数,那么每支队伍都会与另一支队伍配对。总共进行 n / 2 场比赛,…...

【AI论文】RAD: 通过大规模基于3D图形仿真器的强化学习训练端到端驾驶策略
摘要:现有的端到端自动驾驶(AD)算法通常遵循模仿学习(IL)范式,但面临着因果混淆和开环差距等挑战。在本研究中,我们建立了一种基于3D图形仿真器(3DGS)的闭环强化学习&…...

Web开发:ORM框架之使用Freesql的导航属性
一、什么时候用导航属性 看数据库表的对应关系,一对多的时候用比较好,不用多写一个联表实体,而且查询高效 二、为实体配置导航属性 1.给关系是一的父表实体加上: [FreeSql.DataAnnotations.Navigate(nameof(子表.子表关联字段))]…...
【docker】namespace底层机制
Linux 的 Namespace 机制是实现容器化(如 Docker、LXC 等)的核心技术之一,它通过隔离系统资源(如进程、网络、文件系统等)为进程提供独立的运行环境。其底层机制涉及内核数据结构、系统调用和进程管理。以下是其核心实…...

网络编程(Modbus进阶)
思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…...
生成xcframework
打包 XCFramework 的方法 XCFramework 是苹果推出的一种多平台二进制分发格式,可以包含多个架构和平台的代码。打包 XCFramework 通常用于分发库或框架。 使用 Xcode 命令行工具打包 通过 xcodebuild 命令可以打包 XCFramework。确保项目已经配置好需要支持的平台…...

Unity3D中Gfx.WaitForPresent优化方案
前言 在Unity中,Gfx.WaitForPresent占用CPU过高通常表示主线程在等待GPU完成渲染(即CPU被阻塞),这表明存在GPU瓶颈或垂直同步/帧率设置问题。以下是系统的优化方案: 对惹,这里有一个游戏开发交流小组&…...

从深圳崛起的“机器之眼”:赴港乐动机器人的万亿赛道赶考路
进入2025年以来,尽管围绕人形机器人、具身智能等机器人赛道的质疑声不断,但全球市场热度依然高涨,入局者持续增加。 以国内市场为例,天眼查专业版数据显示,截至5月底,我国现存在业、存续状态的机器人相关企…...

Keil 中设置 STM32 Flash 和 RAM 地址详解
文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...

苍穹外卖--缓存菜品
1.问题说明 用户端小程序展示的菜品数据都是通过查询数据库获得,如果用户端访问量比较大,数据库访问压力随之增大 2.实现思路 通过Redis来缓存菜品数据,减少数据库查询操作。 缓存逻辑分析: ①每个分类下的菜品保持一份缓存数据…...

均衡后的SNRSINR
本文主要摘自参考文献中的前两篇,相关文献中经常会出现MIMO检测后的SINR不过一直没有找到相关数学推到过程,其中文献[1]中给出了相关原理在此仅做记录。 1. 系统模型 复信道模型 n t n_t nt 根发送天线, n r n_r nr 根接收天线的 MIMO 系…...
从零手写Java版本的LSM Tree (一):LSM Tree 概述
🔥 推荐一个高质量的Java LSM Tree开源项目! https://github.com/brianxiadong/java-lsm-tree java-lsm-tree 是一个从零实现的Log-Structured Merge Tree,专为高并发写入场景设计。 核心亮点: ⚡ 极致性能:写入速度超…...

Linux入门课的思维导图
耗时两周,终于把慕课网上的Linux的基础入门课实操、总结完了! 第一次以Blog的形式做学习记录,过程很有意思,但也很耗时。 课程时长5h,涉及到很多专有名词,要去逐个查找,以前接触过的概念因为时…...

以太网PHY布局布线指南
1. 简介 对于以太网布局布线遵循以下准则很重要,因为这将有助于减少信号发射,最大程度地减少噪声,确保器件作用,最大程度地减少泄漏并提高信号质量。 2. PHY设计准则 2.1 DRC错误检查 首先检查DRC规则是否设置正确,然…...