SpringBoot 依赖之Spring Web

SpringBoot 依赖之 Spring Web

详细介绍 Spring Web 依赖的内容:

第 1 章:Spring Web
1. 简介

功能描述

  • 英文: Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container.
  • 中文译文:使用 Spring MVC 构建 Web 应用程序,包括 RESTful 应用程序。使用 Apache Tomcat 作为默认嵌入式容器。

Spring Web 提供了构建 Web 应用的基础框架。它支持创建基于 Servlet 的 Web 应用,以及基于 Reactive Streams 的 WebFlux 应用。通过使用 Spring Web,开发者可以轻松构建 RESTful API 和 Web 应用。

2. 配置方法


pom.xml 文件中添加 Spring Web 依赖:

复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
3. 基本用法

下面我们以一个简单的 Spring Boot Web 应用示例,来展示如何创建一个基本的 RESTful API。可以按照代码操作,倾囊输出,源码后期会推送到github或gitee分享。

3.1. 项目结构
复制代码
springboot-web
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── dependencies
│   │   │   │           └── springweb
│   │   │   │               │── SpringWebApplication.java
│   │   │   │               └── controller
│   │   │   │               	└── HelloController.java
│   │   │   └── resources
│   │   │       └── application.properties
│   └── pom.xml
3.2. SpringWebApplication.java
复制代码
package com.dependencies.springweb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringWebApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(SpringWebApplication.class, args);
    }
    
}
3.3. HelloController.java
复制代码
package com.dependencies.springweb.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhizhou   2024/7/23 22:52
 */
@RestController
public class HelloController {
    
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, World!";
    }
}
3.4. 启动应用

运行 SpringWebApplication.java,然后在浏览器中访问 http://localhost:8080/hello,你会看到 Hello, World! 的输出。

4. 高级用法

...有点困,先到这,明天补齐

相关推荐
一 乐8 小时前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
C_心欲无痕8 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
清沫8 小时前
Claude Skills:Agent 能力扩展的新范式
前端·ai编程
yinuo9 小时前
前端跨页面通信终极指南:方案拆解、对比分析
前端
yinuo9 小时前
前端跨页面通讯终极指南⑨:IndexedDB 用法全解析
前端
xiaolyuh1239 小时前
Spring 框架 核心架构设计 深度详解
spring·设计模式·spring 设计模式
xkxnq10 小时前
第二阶段:Vue 组件化开发(第 16天)
前端·javascript·vue.js
烛阴10 小时前
拒绝配置地狱!5 分钟搭建 Three.js + Parcel 完美开发环境
前端·webgl·three.js
期待のcode10 小时前
前后端分离项目 Springboot+vue 在云服务器上的部署
服务器·vue.js·spring boot
xkxnq10 小时前
第一阶段:Vue 基础入门(第 15天)
前端·javascript·vue.js