1 File->new>project->域名加项目名->添加依赖->完成项目



2 由于从maven官网上下载依赖包速度过慢,可以换成国内镜像源,下载速度快一些
右键项目pom.xml->Maven->Open 'settings.xml'
settings.xml文件中添加国内镜像源如代码,效果图如下
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

3 重启IDEA,依赖包下载完毕后,开始书写sprintboot测试代码

A 创建新包步骤,如上图,右键com.example.demo->New->Packet,

B 在frontcontroller下创建,测试类,步骤为 右键frontcontroller->New->Java Class

C 在TestController类中书写测试代码
@RestController
@RequestMapping("/hello")
public class TestController {
@RequestMapping("/hello")
public String hello(){
return "hello world!";
}
}

D 右键DemoApplication run即可,(还可以
,启动右面三角形即可,也可以用maven命令启动)

E 在浏览器中输入 http://localhost:8080/hello/hello,如图成功

本文详细介绍如何使用SpringBoot快速搭建项目,包括配置国内镜像源加速依赖下载,创建项目结构,以及编写和运行测试代码的过程。
1540

被折叠的 条评论
为什么被折叠?



