1分钟基于SpringBoot创建后台服务
1分钟基于SpringBoot创建后台服务
Last edited 2022-9-27
date
Jun 25, 2021
type
Post
status
Published
slug
demo-spring-boot
summary
本文给大家展示基于SpringBoot快速搭建Java后端服务,当然Java开发环境还是需要提前准备好的:1 Jdk1.8安装并配置环境变量;2 Maven安装配置环境变量;3 Idea开发工具安装等
tags
spring-boot
category
spring-boot
password
Property
Sep 27, 2022 02:57 AM
icon

一、SpringBoot介绍

二、两种方式快速创建SpringBoot项目

方式一:spring官网快速生成

1. 浏览器访问地址:https://start.spring.io/

notion image

2. 导入项目到IntelliJ IDEA

  • 解压项目到指定工作空间
  • 用Idea打开项目即可导入,菜单file→open,指定项目文件夹
 

方式二:使用Idea直接快速创建SpringBoot项目

1. 点击菜单 File→ new→ project ,弹出页面

notion image
如果访问不了https://start.spring.io/,可以选择自定义地址,并输入国内地址:https://start.aliyun.com来创建springboot项目。
notion image

2. 修改Java Version

notion image

3. 添加Spring Web依赖

notion image

4. 配置项目名称和路径信息

notion image

5. 点击finish成功创建SpringBoot项目

notion image

6. 有件项目包路径,创建HelloWorldController.java

notion image
notion image
HelloWorldController内容如下:
package com.example.demo.controller; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * hello world * * @author : yi on 2021/6/25 17:36 * @version : 1.0 */ @RestController @RequestMapping("/hello") public class HelloWorldController { @GetMapping public ResponseEntity<String> sayHello() { return ResponseEntity.ok("Hello World!"); } }

7. 启动hello-world项目

右键启动类,启动项目
notion image

8. 启动成功

启动成功的标志:Started DemoApplication in 1.057 seconds (JVM running for 1.685) 默认端口:8080
notion image

9. 浏览器验证

打开浏览器输入:localhost:8080/hello 页面上显示 Hello World即成功!至此,一个简答的SpringBoot项目就搭建完成了!
notion image

三、SpringBoot相关网站

 
 
感谢阅读,祝您生活愉快!
Relate Posts :
  • spring-boot
  • 接口幂等方案【代码这么写】Tree-两行代码返回一颗树