1.先在IDEA配置maven
maven下載和配置可以看https://blog.csdn.net/qq_41150890/article/details/108086369
2.新建maven專案


3.在pom.xml加入springBoot依賴

<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>
4.創建類(用來啟動專案),寫如下代碼

package xiaoliu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringApplicationTest {
public static void main(String[] args) {
//啟動spring應用
SpringApplication.run(SpringApplicationTest.class,args);
}
}
5.創建Controller 寫代碼如下

5.運行


6.訪問專案
在頁面中輸入http://localhost:8080/hello 即可訪問專案,

可以用idea 打包 成jar
然后用 java -jar hello.jar 運行springboot 專案
springboot中已經自帶了tomcat,所以可以沒有tomcat環境
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/168183.html
標籤:其他
