1.系统要求
① Java 8 & 兼容Java 14
② maven3.3+
1.1 maven设置
将下面配置加入setting.xml中(找个空位置加进去,注意不要重复了);
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
2.HelloWorld
需求:浏览器发送/hello请求,响应 Hello springboot!
2.1 创建maven工程
2.2 引入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
将上述代码加入pom.xml文件中(注意需要网络下载配置中的jar包)
2.3 创建主程序
package com.bbu.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //声明为Springboot程序
public class Test {
public static void main(String[] args) {
SpringApplication.run(Test.class,args);
}
}
2.4 编写业务逻辑
package com.bbu.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle(){
return "Hello Springboot!";
}
}
如图:
2.5 测试
直接运行主类main方法;(我用的是idea2020版)
出错了不要慌:更改下图,再重启就行:
恭喜你,成功了:
浏览器输入:localhost:8080/hello,测试应用
如有错误,欢迎指正