JavaWeb-18-Spring介绍

Spring介绍


1. 为什么选择Spring?

image-20230826193135701

image-20230826193120398


image-20230826193309810

image-20230826193428386



2. Spring项目介绍

  • Spring发展到今天已经形成了一种开发生态圈,Spring提供了若干个子项目,每个项目用于完成特定的功能。

image-20230826193153460


  • Spring家族开发的这么多子项目其实都是基于一个基础框架:Spring Framework

    image-20230826193724212

  • 如果在项目当中我们直接基于基础框架:Spring Framework来开发会存在两大问题:

    image-20230826193751191

  • Spring家族意识到这点之后,又人性化的推出了Spring Boot

    • Spring Boot 可以帮助我们非常快速的构建应用程序、简化开发、提高效率。
    • 当然,Spring Boot只是简化Spring应用的配置和开发,底层还是Spring。

    image-20230826193804830

    image-20230826193932800

    image-20230826194058692

    image-20230826194158419



SpringBootWeb-快速入门

1. 实现

  • 需求:使用 SpringBoot 开发一个web应用,浏览器发起请求 /hello后,给浏览器返回字符串 “Hello World ~”

    image-20230826194244892

  • 实现步骤:

    ① 创建springboot工程,并勾选web开发相关依赖。

    image-20230826194359076

    image-20230826194849984

    image-20230826195034161

    image-20230826195139016


    • 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>
    
        <!-- 继承:指定父工程 -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.7.15</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <!-- 当前项目坐标信息 -->
        <groupId>com.app</groupId>
        <artifactId>springboot-web-quickstart</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <!-- 项目描述信息 -->
        <name>springboot-web-quickstart</name>
        <description>springboot-web-quickstart</description>
    
        <!-- jdk版本 -->
        <properties>
            <java.version>11</java.version>
        </properties>
    
        <!-- 配置依赖 -->
        <dependencies>
            <!-- spring boot进行web开发的依赖 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!-- 单元测试依赖 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <!-- 插件 -->
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    ② 为了项目的简洁,删除无用的目录和文件

    image-20230826195827116

    image-20230826200349362


    ③ 定义HelloController类,添加方法 hello,并添加注解。

    image-20230826201120676


    ④ 运行测试

    image-20230826201438029

    image-20230826201505144

    image-20230826201701443


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值