在枯燥學習spring之後(其實也沒學啥,找不到IEDA版本的Spring視頻,希望在座的大佬提供資源)開始入手Spring boot。使用的開發軟件是IDEA,使用maven創建項目
目錄
六、在瀏覽器中輸入http://localhost:8080/hello即可出現結果
一、項目整體
二、在pom.xml進行如下jar包配置
<?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>com.yongjie</groupId>
<artifactId>Spring-boot-01-hello</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!--可以將當前項目打成一個jar報運行-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
三、創建控制層HelloController類
package com.yongjie.hello;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller//控制層註解
public class HelloController {
@ResponseBody
@RequestMapping("/hello")//請求路徑
public String hello(){
return "hello world......";
}
}
四、創建主程序Main方法
package com.yongjie;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication//用於標識,一個引導類表示爲主程序類
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class,args);
}
}
五、控制檯運行結果
六、在瀏覽器中輸入http://localhost:8080/hello即可出現結果