1.新建maven项目(打包成jar包)
2.在pom.xml添加spring-boot-starter-web依赖,并更新
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.写一个控制器如下,然后写一个main方法,把程序跑起来:
@RestController //相当于声明Controller - 提共restful 风格 @EnableAutoConfiguration //自动配置,不需要写spring的配置文件 public class HelloController { @RequestMapping("hello") @ResponseBody public String hello(){ return "hello spring boot:2019-10-15"; } public static void main(String[] args) { //启动程序 SpringApplication.run(HelloController.class,args); } }
public static void main(String[] args) {
//启动程序
SpringApplication.run(HelloController.class, args);
}
}