SpringBoot初始——HelloWord
pom文件中:
<!--SpringBoot超级父pom,用于约定好各种jar依赖的版本号-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<dependencies>
<!--引入web部分的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--提供了一些方便程序开发的功能-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<!--插件,可以让SpringBoot项目package成jar文件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.properties文件(存到resources资源文件夹下)中:
#配置启动的端口号
server.port=8080
启动类存放的位置及代码信息:
package com.tt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class RunSpringBoot {
public static void main(String[] args) {
SpringApplication.run(RunSpringBoot.class, args);
}
}
书写控制层代码
package com.tt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping("/test")
public String test(){
System.out.println("嘿嘿");
return "HelloWorld-->zhangzhe";
}
}
最后在IDEA中的setting配置上 --> Maven --> Importing 中勾选build project automatically
启动后浏览器地址栏中输入:localhost:8080/test,效果如下