一、創建一個Maven工程,
2.
4.
next
在pom.xml文件中添加啓動依賴
<!--springboot要求,項目要繼承spring-boot-starter-parent起步依賴--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> </parent> <dependencies> <!--web功能,項目要繼承spring-boot-starter-web起步依賴--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
創建引導類
package com.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @Auther zhishuaijun * 這個啓動類的 名字叫什麼都可以 * @Date 2019/10/25 11:21 */ @SpringBootApplication public class MySpringBootApplication { //psvm鍵+alt+Enter快速生成main public static void main(String[] args) { SpringApplication.run(MySpringBootApplication.class, args); } }
創建controller
package com.springboot.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * @Auther zhishuaijun * @Date 2019/10/25 11:47 */ @Controller public class SpringBootHelloController { @RequestMapping("/hello") @ResponseBody public String hello(){ return "hello SpringBoot"; } }
完成。瀏覽器輸入http://localhost:8080/hello
結果如下: