一、首先建立一个maven项目
这里什么也不选直接next。
填写自己的GAV,这样一个醒目就建好了。
二。添加springboot POM文件信息。
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.21.RELEASE</version>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
三。写一个controller和一个springboot application启动类。
HelloController.java
package com.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Description:
* User: zwh
* Date: 2019-06-08
* Time: 9:55
*/
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String sayHello(){
return "hello this is spring boot demo";
}
}
HelloApplication.java
package com.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Description:
* User: zwh
* Date: 2019-06-08
* Time: 9:56
*/
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class,args);
}
}