当前位置: 首页 > ai >正文

spring boot启动

maven

        maven类似于php里面的composer,包管理工具。

安装maven链接https://cloud.tencent.com/developer/article/1994055

Idea创建项目

在idea中创建一个spring boot项目

依赖选择spring web

JDK8更改pom.xml

由于我使用的是jdk8,spring boot需要更换一下版本。

pom.xml类似于php的composer.json,不过php使用的是json,java使用的是xml。

<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>demo</name><description>Demo project for Spring Boot</description><!-- JDK 8 要用 2.7.x --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.18</version><relativePath/> <!-- lookup parent from repository --></parent><properties><java.version>1.8</java.version></properties><dependencies><!-- 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><!-- Spring Boot 插件 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>

写第一个接口

        项目结构

src└── main├── java│   └── com.example.demo│       └── DemoApplication.java   # 启动类└── resources├── application.properties     # 配置文件

com.example.demo 下建一个 HelloController.java

package com.example.demo;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@GetMapping("/hello")public String hello() {return "Hello, Spring Boot!";}
}

编译运行

访问http://localhost:8080/hello

spring boot第一个接口启动完成。

http://www.xdnf.cn/news/19603.html

相关文章:

  • CAN诊断箱调试报告
  • Kubernetes 高级健康检查与存储卷详解
  • 质量安全管控如何实现事前预防?
  • hadoop 框架 jar下载
  • Python入门教程之类型转换
  • 别被亚马逊FBA拖垮!合规入仓+高效履约,全链路痛点破解指南来了
  • 视频转文字软件哪个免费好用?2025年5款实用工具实测,助力办公效率!
  • Linux 内核定时器实验
  • 日语学习-日语知识点小记-构建基础-JLPT-N3阶段(24):文法+单词第8回1
  • 小迪web自用笔记24
  • Unity切换平台资源重新编译缓慢
  • 从C语言入门到精通:代码解析与实战
  • 解锁复杂工作流:Roo Code 中的「Boomerang Tasks」机制 : Orchestrator Mode 的使用
  • 2025年09月02日Github流行趋势
  • 会议签到存证系统设计与实现
  • Jenkins 拉取 Git 仓库时报错:there are still refs under ‘refs/remotes/origin/release‘
  • 在 Elasticsearch 中使用用户行为分析:使用 UBI 和 search-ui 创建一个应用程序
  • Python 实战:内网渗透中的信息收集自动化脚本(8)
  • vue飞自在酒店管理系统(代码+数据库+LW)
  • 25.9.2_NSSCTF-[HNCTF 2022 WEEK2]TTTTTTTTTea_WP
  • 【读论文】美团开源MOE大模型LongCat-Flash
  • YOLO 目标检测:YOLOv5网络结构、Focus、CSP、自适应Anchor、激活函数SiLU、SPPF、C3
  • 还在用Excel?Pandas数据处理效率翻倍
  • 好起来了!又一地公布5月软考合格人员名单!高级通过率上升2.28%!
  • 蓝桥杯算法之基础知识(4)
  • 一款为开发者而生的开源全栈LLMOps平台
  • CMake构建学习笔记23-SQLite库的构建
  • 基于Django的论坛系统设计与实现(代码+数据库+LW)
  • 国内外商用版权音乐授权平台大盘点:核心优势与选择指南
  • UniApp 实现搜索页逻辑详解