創(chuàng)建maven快速啟動項目
命令行或者idea、eclipse快捷創(chuàng)建也可以
pom.xml下project項目下導入springboot 父工程
<!--導入springboot 父工程-->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.5.3</version>
</parent>
導入springboot啟動器
<dependencies>
<!--導入web項目場景啟動器 會自動導入和web開發(fā)相關的依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
編寫啟動類
package com.wujialiang.springboot01;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* spring boot啟動類
*
*/
@SpringBootApplication
public class App {
public static void main(String[] args) {
// 第一個參數(shù)是該類的名字.class 第二個參數(shù)是main方法中的參數(shù)
SpringApplication.run(App.class, args);
}
}
啟動項目
訪問loalhost:8080,因為沒有其他接口所以報錯
新建controller文件夾
新建HelloController.java文章來源:http://www.zghlxwxcb.cn/news/detail-693121.html
package com.wujialiang.springboot01.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/")
public String hello() {
return "Hello World";
}
}
重新啟動項目訪問文章來源地址http://www.zghlxwxcb.cn/news/detail-693121.html
到了這里,關于使用maven創(chuàng)建springboot項目的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!