✨【一心同学】的写作风格:喜欢用【通俗易懂】的文笔去讲解每一个知识点,而不喜欢用【高大上】的官方陈述。
✨【一心同学】博客的领域是【面向后端技术】的学习,未来会持续更新更多的【后端技术】以及【学习心得】。
✨如果有对【后端技术】感兴趣的【小可爱】,欢迎关注【一心同学】💞💞💞
❤️❤️❤️**感谢各位大可爱小可爱!**❤️❤️❤️
本章主要讲解三种方式对Spring的搭建,开始入门SpringBoot。
- 使用官网搭建SpringBoot
- 手动搭建SpringBoot
- 使用IDEA搭建SpringBoot
目录
环境准备
开发工具
1、使用官网搭建SpringBoot
2、手动搭建SpringBoot
补充
3、使用IDEA搭建SpringBoot(推荐)
结语
环境准备
====
java:1.8
Maven:3.3.9
SpringBoot:2.X
开发工具
====
IDEA:2020
1、使用官网搭建SpringBoot
==================
(1)打开官网:https://start.spring.io/
(2)填写要创建项目的基本信息
(3) 点击GENERATE进行下载。
(4) 解压到指定目录。
(5) 用IDEA进行导入
(6) 编写测试Controller
注意:务必要在主程序SpringBootTestApplication同级目录下进行创建。
package com.yixin.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@RequestMapping(“/hello”)
public String hello(){
return “hello world”;
}
}
点击运行主程序SpringBootTestApplication。
浏览器测试:
第一种方式搭建成功。
2、手动搭建SpringBoot
================
(1)创建一个Maven项目
(2)在pom.xm导入以下依赖及配置。
parent>
org.springframework.boot
spring-boot-starter-parent
2.6.2
org.springframework.boot
spring-boot-starter-web
(3)编写主程序(启动Spring Boot应用)
package com.yixin.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
// Spring应用启动起来
SpringApplication.run(HelloWorldMainApplication.class,args);
}
}
(4)编写相关的Controller测试
注意:务必跟主程序在同级目录下。
package com.yixin.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@RequestMapping(“/hello”)
public String hello(){
return “Hello World!”;
}
}
(5)运行主程序测试
第二种方式到此就大功告成了!
补充
如果希望将应用打成jar包,直接使用java -jar的命令进行执行,那么应在pom.xml进行如下配置。
org.springframework.boot
spring-boot-maven-plugin
3、使用IDEA搭建SpringBoot(推荐)
========================
(1)创建一个新项目