使用idea构建SpringBoot项目
新建项目-->选择maven(不使用骨架)-->填写groupId和artifactId。。。和创建普通maven工程一致-->finish
pom.xml添加内容
<!--SpringBoot启动器作为父工程-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<!--引入web工程启动器-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
编写启动类
package com.company;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//没有配置扫描,默认扫描启动类所在的包
@SpringBootApplication
public class BootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(BootDemoApplication.class,args);
}
}
编写测试类,默认端口8080
package com.company.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//作用=@Controller+@ResponseBody
public class HelloController {
@GetMapping("/hello")//作用=@RequestMapping(method = {RequestMethod.GET})public String hello(){
return "hello Springboot!";
}
}
hello Springboot!