用idea搭建springboot
1、首先先配置好maven
链接:https://editor.csdn.net/md/?articleId=109404762
2、创建项目,选择maven
右下角,next
3、然后就是取名,项目位置
然后就是finish了
4、修改pom.xml
要添加springboot,
也可以看spring boot官网链接
https://spring.io/guides/gs/rest-service/
复制下面的,注意spring-boot-starter-parent的version和Java的version
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<name>rest-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
复制好后,要下载导入包,需要时间。
5、创建main类(我的是test)和hello类
main类:
package com.nineManagement;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class test {
public static void main(String[] args) {
SpringApplication.run(test.class, args);
}
}
hello类:
package com.nineManagement.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class Hello {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "hello world!";
}
}
6、最后就是启动spring了
右上角,三角形运行,不行就进入main类右键run
稍等,好了之后,进入浏览器
localhost:8080
然后在后面加hello
localhost:8080/hello
就有输出了
至于里面的原理,就自行学spring和spring boot等等。