1.项目目录:
- src ??? -main ?? ?-java ?? ???? -package ?? ??? ?-SpringbootApplication --------------- 程序的入口 ??????? -resouces ------------------------------------ resouces 资源文件 ?? ???? - statics -------------------------------- 静态资源 ??????????? - templates ------------------------------ 模板资源 ?? ???? - application.properties ----------------- 配置文件 ??? -test - pom ------------------------------------------------ pom文件为基本的依赖管理文件

1.1主函数Demo1Application代码:
package com.example.demo1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class Demo1Application {
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
}
@GetMapping("/demo1")
public String demo() {
return "Hello World!";
}
}
1.2.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>com.wzp</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- 项目名字 以及项目描述-->
<name>wzp</name>
<description>Demo project for Spring Boot</description>
<!--版本采用的是最新的 2.1.1.RELEASE -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--该依赖包含spring-boot-starter,还自动开启了web功能 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
?1.3修改配置文件
在配置文件(application.properties)里修改端口号以及访问路径等,修改后的访问路径就是: http://localhost:8080/demo1
(注意端口号是8080就不用修改了这是是8080改为9090的方法)
# 默认端口号是 8080 我们可以把它改成 9090
server.port=9090
# 也可以更改访问路径
server.servlet.context-path=/wzp
1.4启动项目后直接访问 http://localhost:8080/demo1 进行测试
注意这里的路径是你自己设置的或者自己建立的项目名,不要照抄代码

2.遇到的问题:
1.创建springboot项目时,出现connect time out的错误提醒

1.1、打开防火墙,点击允许程序通过Window 防火墙

1.2、点击IDEA程序允许在专用和公用网络,点击确认

1.3现在在创建项目就OK了
有时会又有问题,将弹出的错误提示框复制百度,将所有方法试一遍
2.建的项目报错 程序包org.junit.jupiter.api不存在


?鼠标放在 报错的 Test 上选择 Add ...to classpath,项目会自动导入相关依赖,要注意必须联网

|