第一节: 创建 SpringBoot 项目并运行 HelloWorld
SpingBoot 365 计划开始更新了,计划手敲 365 个 SpringBoot 案例回顾总结形成知识体系。目前已经输出了 32 节的内容。所有源码托管在 GitHub 和 Gitee 上。
1.第一节:创建 SpringBoot 项目并运行 HelloWorld.md
2.第二节:SpingBoot 单元测试.md
3.第三节:SpringBoot 中 web 项目推荐目录结构.md
4.第四节:SpringBoot 中 web 模版数据渲染展示.md
5.第五节:SpringBoot 常用注解介绍.md
6.第六节:SpingBoot 基本配置一.md
7.第七节:SpringBoot 高级属性配置二.md
8.第八节:SpringBoot 指定配置文件配置三.md
9.第九节:SpringBoot 在线文档 Swagger2 入门.md
10.第十节:SpringBoot 中的日志管理.md
11.第十一节:Springboot 整合 log4j2 日志.md
12.第十二节:Springboot 多环境配置.md
13.第十三节:使用 Lombok 简化你的代码.md
14.第十四节:SpringBoot 使用 JdbcTemplate 访问操作数据库基本用法.md
15.第十五节:SpringBoot 使用 JPA 访问数据库.md
16.第十六节:SpringBoot 使用 JPA 一对多,多对多访问数据库.md
17.第十七节:SpringBoot 使用 JPA 实现用户角色多对多查询.md
18.第十八节:SpringBoot 集成 MyBatis 注解方式访问数据库.md
19.第十九节:SpringBoot 集成 MyBatis(XML)方式访问数据库.md
20.第二十节:SpringBoot 集成 MyBatis 实现分页.md
21.第二十一节:SpringBoot 使用 Mybatis
22.第二十二节:SpringBoot 集成 MyBatis-Plus 实现增删改查.md
23.第二十三节:SpringBoot 统一异常处理 3 种方式.md
24.第二十四节:SpringBoot 中数据校验 JSR303.md
25.第二十五节:SpringBoot 中自定义一个 JSR303 规范的注解校验器.md
26.第二十六节:SpringBoot 集成 Redis 配置的基本操作.md
27.第二十七节:SpringBoot 中的 stream 实现消息队列.md
28.第二十八节:SpringBoot 中使用 Redis 实现超时取消订单.md
29.第二十九节:SpringBoot 中 Redis 实现消息订阅.md
30.第三十节:SpringBoot 集成 ehcache 使用 JVM 内存模式缓存.md
31.第三十一节:SpringBoot 集成 ehcache 使用 Redis 模式缓存.md
32.第三十二节:SpringBoot 集成 WebSocket.md
未完待续。。。。。
什么是 SpringBoot
Spring Boot 是 Pivotal 于 2014 年开发的开源 Java 框架,简化了部署 Java 企业 Web 应用程序的任务。它是一个构建在 Spring 框架之上的项目,它简化了 Java 开发。
SpringBoot 和 Spring 的关系

SpringBoot 的优点
快速轻松地开发基于 Spring 的应用程序;
无需部署 war 文件;
帮助将 Tomcat、Jetty 或 Undertow 直接嵌入到应用程序中;
无需 XML 配置
上面简单介绍了 SpringBoot,下面我们就开始创建并运行一个 SpringBoot 项目
开发环境
JDK1.8
Maven 3.6.1
SpringBoot 2.5.6
先创建一个父工程
创建一个父工程包含每一小节的项目案例,也就是说每一小节的项目都是一个模块。
打开 idea
点击 Create New Project ,创建一个新项目

选择 Maven 项目,右边不要勾选(不选择模板)

选择项目创建的位置

删除 src 目录

创建一个 SpringBoot 项目
左边选择项目目录右键 New 一个 Module

选择 Spring Initializr 创建 SpringBoot 项目

输入 Maven 坐标和选择 Java 版本

选择 Developer Tools 中的 Spring Boot DevTools
Spring Boot DevTools 模块能够实现热部署,添加类.添加方法,修改配置文件,修改页面等,都能实现热部署.

选择 Web 中的 Spring Web
我们演示的是 Java Web 项目,所以要选择 Spring Web

这样我们的项目就创建好了
创建入门的 Hello World 程序
创建lession1.controller
包。

创建HelloWorldController.java
文件
创建
com.rumenz.helloworld.controller.HelloWorldController.java

@RestController
注解是一种快捷方式,它所声明的控制器在返回响应时,就如同使用了@ResponseBody
注解一样。它会告诉 Spring 将返回类型序列化为合适的格式,默认情况下为 JSON 格式。通过用@RestController
注释控制器类,你不再需要向所有请求映射方法添加@ResponseBody
@GetMapping
是一个组合注释,相当于@RequestMapping(method = RequestMethod.GET)
.
启动项目
Lession1Application
是项目启动类,是默认生成的,默认端口是8080
, 选中右键-> Run As –> Java Application

浏览器访问 http://127.0.0.1:8080/

至此我们的第一个 SpingBoot 项目就创建并启动起来了。
本小结源码地址:
GitHub:https://github.com/mifunc/springboot/tree/main/lession1
Gitee:https://gitee.com/rumenz/springboot/tree/master/lession1
原文:https://rumenz.com/rumenbiji/springboot-helloworld.html
介绍
我的博客 https://rumenz.com/ ,
我的工具箱 https://tooltt.com/
微信公众号:【入门小站】

关注【入门小站】回复【1001】获取 linux 常用命令速查手册
关注【入门小站】回复【1003】获取 LeetCode 题解【java 语言实现】
关注【入门小站】回复【1004】获取 Java 基础核心总结
关注【入门小站】回复【1009】获取 阿里巴巴 Java 开发手册
版权声明: 本文为 InfoQ 作者【入门小站】的原创文章。
原文链接:【http://xie.infoq.cn/article/b3152ee2b288b44cb18592903】。文章转载请联系作者。
评论