1.先创建一个普通的Maven工程
2.在创建完成的Maven的pom.xml文件中引入spring-boot-starter-parent(必需)
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.7.2</version>
</parent>
3.然后在pom.xml文件中再引入spring-boot-starter-web(必需)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
其余的jar包就按照自己的需要引入
4.在resources中创建application.yml(或application.properties)文件
文件名必须为application开头
在创建完成的application.yml中写入自己需要的数据
5.在java目录下创建MainApplication
MainApplication中代码:
package com.lqh;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author Li Qinghua
* @Create 2022/7/22 10:47
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
这样在没有网络的情况下,一个SpringBoot工程文件就创建完成了
6.测试Springboot
创建controller层和controller文件
package com.lqh.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* @Author Li Qinghua
* @Create 2022/7/22 10:51
*/
@RestController
public class HelloController {
@RequestMapping(value = "/hello")
public Map testHello(){
Map map=new HashMap();
map.put("name","LiQinghua");
map.put("age",23);
return map;
}
}
运行结果: