【springboot】1、快速入门
  TEZNKK3IfmPf 2023年11月12日 23 0

springboot是什么

Spring Boot 是所有基于 Spring 开发的项目的起点。Spring Boot 的设计是为了让你尽可能快的跑起来 Spring 应用程序并且尽可能减少你的配置文件。简单来说就是SpringBoot其实不是什么新的框架,它默认配置了很多框架的使用方式,就像maven整合了所有的jar包,spring boot整合了所有的框架

spring的基本介绍

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”.

We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need minimal Spring configuration.

这里就是官方对springboot的说明,翻译过来就是Spring Boot 可以轻松创建可以“直接运行”的独立的、生产级的基于 Spring 的应用程序。springboot对 Spring 平台和第三方库持固执己见的看法,因此您可以轻松上手。大多数 Spring Boot 应用程序需要最少的 Spring 配置。

springboot的特征

  • 创建独立的 Spring 应用程序
  • 直接嵌入 Tomcat、Jetty 或 Undertow(无需部署 WAR 文件)
  • 提供自以为是的“入门”依赖项以简化您的构建配置
  • 尽可能自动配置 Spring 和 第三方库
  • 提供生产就绪功能,例如指标、健康检查和外部化配置
  • 完全无需代码生成,无需 XML 配置

springboot基本使用

创建maven项目

先创建一个干净的maven项目

【springboot】1、快速入门

引入springboot父项目

在pom.xml中引入springboot的父项目

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version>
    </parent>

引入web依赖

在pom.xml中引入依赖

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
     </dependency>

创建一个Controller

springboot其实就是基于spring的,spring和springmvc中的用法在springboot中基本没变,我们来创建一个Controller来进行测试

@RestController
public class TestController {
     
       
    
    @RequestMapping("/t1")
    public String t1(){
     
       
        return "success";
    }
}

创建一个启动类

@SpringBootApplication
public class App {
     
       
    public static void main(String[] args) {
     
       
        SpringApplication.run(App.class);
    }
}

注意:springboot中,默认扫描路径是启动类所在的包以及它的子包,我们使用@SpringBootApplication来标识启动类,在main方法中启动,具体细节后面说明。我的项目结构如下
【springboot】1、快速入门

运行springboot程序

我们启动运行 自己创建的启动类,控制台输出如下
【springboot】1、快速入门
然后我们来访问一下前面创建的Controller,端口默认是8080,访问地址就是http://localhost:8080/t1,访问该网页,显示如下,访问成功
【springboot】1、快速入门

总结

到此,springboot的基本使用就说明完成了,springboot的其它用法以及细节说明在后面文件进行讲解

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月12日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   25天前   51   0   0 java