当前位置:网站首页>02_SpingBoot 入门案例
02_SpingBoot 入门案例
2022-06-24 19:41:00 【书启秋枫】
1. 创建一个空项目Empty Project
2. 项目文件名为 SpringBoot
3. 选择Create创建即可
4. 选择 File --》New --》Moudle 创建模块
5. 选择命名该项目相关联的信息配置
6. 选择 Web --》Spring Web
7. 项目结构介绍
(1) .mvn|mvnw|mvnw.cmd:使用脚本操作执行maven相关命令,国内使用较少,可删除
(2) .gitignore:使用版本控制工具git的时候,设置一些忽略提交的内容
(3) static|templates:后面模板技术中存放文件的目录
static:放一些静态内容 css js img
templates:基于模板的html
(4)application.properties:SpringBoot的配置文件,很多集成的配置都可以在该文件中进行配置,例如:Spring、springMVC、Mybatis、Redis等。目前是空的
(5) Application.java:SpringBoot程序执行的入口,执行该程序中的main方法,SpringBoot就启动了,自动启动内置tomcat运行
8. 介绍 SpringBoot 启动入口类
9. pom.xml 默认自动配置详情介绍
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--继承SpringBoot框架的一个父项目,所有自己开发的Spring Boot都必须的继承-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--当前项目的GAV坐标-->
<groupId>com.suke.springboot</groupId>
<artifactId>springboot-first</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--maven项目名称,可以删除-->
<name>001-springboot-first</name>
<!--maven项目描述,可以删除-->
<description>001-springboot-first</description>
<!--maven属性配置,可以在其它地方通过${}方式进行引用-->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--SpringBoot框架web项目起步依赖,通过该依赖自动关联其它依赖,不需要我们一个一个去添加了-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--SpringBoot框架的测试起步依赖,例如:junit测试,如果不需要的话可以删除-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<!--修建:编译-->
<build>
<!--编译哪个资源-->
<resources></resources>
<!--插件-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.0</version>
</plugin>
</plugins>
</build>
</project>
10. 运行输入localhost:9001/001-springboot-first/springBoot/say显示成功
11. 入门案例总结分析
Spring Boot的父级依赖spring-boot-starter-parent配置之后,当前的项目就是Spring Boot项目
spring-boot-starter-parent是一个Springboot的父级依赖,开发SpringBoot程序都需要继承该父级项目,它用来提供相关的Maven默认依赖,使用它之后,常用的jar包依赖可以省去version配置
Spring Boot提供了哪些默认jar包的依赖,可查看该父级依赖的pom文件
如果不想使用某个默认的依赖版本,可以通过pom.xml文件的属性配置覆盖各个依赖项,比如覆盖Spring版本
<properties>
<spring.version>5.0.0.RELEASE</spring.version>
</properties>
@SpringBootApplication注解是Spring Boot项目的核心注解,主要作用是开启Spring自动配置,如果在Application类上去掉该注解,那么不会启动SpringBoot程序
main方法是一个标准的Java程序的main方法,主要作用是作为项目启动运行的入口
@Controller 及 @ResponseBody 依然是我们之前的Spring MVC,因为Spring Boot的里面依然是使用我们的Spring MVC + Spring + MyBatis 等框架
边栏推荐
猜你喜欢
Pousser l'information au format markdown vers le robot nail
Web security XSS foundation 06
Combine pod identity in aks and secret in CSI driver mount key vault
ThreadLocal memory leak
环境配置 | VS2017配置OpenMesh源码和环境
动态菜单,自动对齐
JWT(Json Web Token)
[text data mining] Chinese named entity recognition: HMM model +bilstm_ CRF model (pytoch) [research and experimental analysis]
2022年高压电工考试模拟100题及在线模拟考试
ThreadLocal local thread
随机推荐
机器学习编译入门课程学习笔记第一讲 机器学习编译概述
Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
Tetris
OSPF basic content
[postgraduate entrance examination English] prepare for 2023, learn list9 words
是否需要提高代码阅读能力?这有技巧
The difference between get and post
ThreadLocal local thread
MySQL夺命10问,你能坚持到第几问?
07_SpingBoot 实现 RESTful 风格
The large-scale market of graduate dormitory! Here comes the enviable graduate dormitory!
推送Markdown格式信息到釘釘機器人
Recommended course: workplace writing training
EPICS记录参考2--EPICS过程数据库概念
Combine pod identity in aks and secret in CSI driver mount key vault
2022年安全员-A证考题及答案
Rip protocol of dynamic routing protocol
Leetcode algorithm The first common node of two linked lists
Research Report on market supply and demand and strategy of China's solar charging controller industry