1.創(chuàng)建maven項目
2.編寫springboot的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>org.example</groupId>
<artifactId>springbootdemo1</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
所用的spring boot 項目會直接或者間接的繼承spring-boot-starter-parent
1.指定項目的編碼格式 為UTF-8
2.指定JDK版本為1.8
3.對項目依賴的版本進行管理埠戳,當前項目再引入其他常用的依賴時無需指定版本號,避免版本沖突
4.默認的資源過濾和插件管理
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
</parent>
<dependencies>
<!-- 引入spring-web 和spring-mvc相關(guān)的依賴-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!--可以將project打包為可執(zhí)行的jar-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.創(chuàng)建相關(guān)包和類
其二級包必須有啟動類肮韧,類中必須有main方法
package com.lagou;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author 絕~~念
* @Date 2022/6/15 10:18
* @Version 1.0
*
*
*
* SpringBoot的啟動類
* 放于二級包中
* SpringBoot做包掃描時窜骄,會掃描啟動類所在的包及其子包下的內(nèi)容
*/
//標識當前類為springboot的啟動類
@SpringBootApplication
public class SpringBootDemo1Application {
public static void main(String[] args) {
//1.獲取當前啟動類的字節(jié)碼文件
//2.main函數(shù)的方法參數(shù)
SpringApplication.run(SpringBootDemo1Application.class,args);
}
}
controller
package com.lagou.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author 絕~~念
* @Date 2022/6/15 10:06
* @Version 1.0
*/
/*
組合注解:
@Controller(將CourseController類進行實例化贩疙,存儲到IOC容器中)
@ResponseBody(告知springMVC不要進行頁面跳轉(zhuǎn),直接回寫數(shù)據(jù))
* */
@RestController
@RequestMapping("/hello")
public class TestController {
@RequestMapping("/boot")
public String helloBoot(){
return "Hello Spring Boot";
}
}