springboot第一個專案hello word (1)
阿新 • • 發佈:2018-12-11
我用的是idea版的
新建一個專案,我就不具體說了。主要說重要的。
開啟pom.xml 配置依賴
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--核心依賴--> <groupId>pringbooth</groupId> <artifactId>pringbooth</artifactId> <version>1.0-SNAPSHOT</version> <parent><!--SpringBoot配置--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version> </parent> <dependencies> <dependency><!--Web的基本配置--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin><!--plugin配置--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
然後新建一個類,寫上主方法,執行即可
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @EnableAutoConfiguration public class Ha { @RequestMapping("/hello")//接受瀏覽器的hello請求 @ResponseBody//spring的用法 String home(){ return"Hello Word"; } public static void main(String[] args) { SpringApplication.run(Ha.class, args); } }
啟動主程式,開啟瀏覽器訪問http://localhost:8080/hello,就可以看到效果了