当前位置:首页 > 编程笔记 > 正文
已解决

SpringBoot3基础:最简项目示例

来自网友在路上 170870提问 提问时间:2023-09-21 10:22:26阅读次数: 70

最佳答案 问答题库708位专家为你答疑解惑

说明

本文建立一个最基本的SpringBoot3项目,依赖项仅包含 spring-web(SpringMVC)

备注:SpringBoot3需要JDK17支持,配置方法参考:
SpringBoot3项目中配置JDK17

项目结构图示

在这里插入图片描述

POM

<?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>3.1.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>hello-spring-boot3</artifactId><version>1.0</version><name>HelloSpringBoot3</name><description>Demo project for Spring Boot3</description><properties><java.version>17</java.version></properties><dependencies><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><dependencyManagement><dependencies><dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>2.0</version></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

启动器:Application

package com.example;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class HelloSpringBoot3Application {public static void main(String[] args) {SpringApplication.run(HelloSpringBoot3Application.class, args);}}

配置文件:yml

使用的默认配置,未添加任何内容。

控制器:Controller

package com.example.web.controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("test")
public class TestController {@GetMapping("hello")public String hello() {return "Hello SpringBoot3";}}

接口调用示例

在这里插入图片描述

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"SpringBoot3基础:最简项目示例":http://eshow365.cn/6-10626-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!