脚手架项目(开局只有一个idea,从零到一肝脚手架)

项目仓库

day01

环境准备

  1. git
  2. maven
  3. apifox

建立git仓库(gitee)

  1. 创建一个仓库

20240201155414.png

1706774611968.png

1706774724930.png

  1. git bash克隆

1706775178545.png

win + x ,选择终端管理员(A) ,打开命令行工具(注意文件的路径)

1
git clone https://gitee.com/higanbana-0/ape-frame.git

克隆到本地,用idea打开

或者idea克隆

1706775860895.png

1706775990168.png

初始化项目

  1. 修改pom.xml文件

以下pom.xml若无特别说明,均指ape-frame/pom.xml

1
2
3
4
5
6
7
8
9
10
11
<?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.higanbana</groupId>
<artifactId>ape-frame</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
</project>

注意maven的设置
1706776992647.png

添加为maven项目,右键pom.xml -> Add as Maven Project

  1. 设置阿里镜像pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- 阿里云仓库 -->
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<!-- 是否开启发布版构件下载 -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 是否开启快照版构件下载 -->
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

新建ape-user模块

右键ape-frame -> New -> Module

1706778130732.png

pom.xml(ape-user)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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>
<parent>
<groupId>com.higanbana</groupId>
<artifactId>ape-frame</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>ape-user</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>

新建ape-common模块

右键ape-frame -> New -> Module

引入springboot(pom.xml)

1
2
3
4
5
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.4.2</version>
</parent>

配置build —>plugins(pom.xml)

1
2
3
4
5
6
7
8
9
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>

为了统一版本管理

1
2
3
4
5
6
<!-- 统一管理jar包版本 -->
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.plugin.version>3.10.1</maven.plugin.version>
</properties>

有了统一版本管理,可以将maven-compiler-plugin的版本号改为

1
2
3
4
5
6
7
8
9
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.plugin.version}</version>
</plugin>
</plugins>
</build>

同理,设置configuration

1
2
3
4
5
6
7
8
9
10
11
12
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
1
2
3
4
5
6
7
8
<!-- 统一管理jar包版本 -->
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.plugin.version>3.10.1</maven.plugin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

打包目录

1
2
3
4
5
6
7
8
9
10
11
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>

创建启动类

ape-user/src/main/java 目录下创建包 com.higanbana.user

在包下创建启动类 UserApplication

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.higanbana.user;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.swing.*;

@SpringBootApplication
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class);
}
}

对于@SpringBootApplication 注解,在pom.xml文件中添加spring-boot-starter-web依赖

1
2
3
4
5
6
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

ape-user/src/main/resources 目录下创建文件 application.yml

1
2
server:
port: 8080

测试

ape-user/src/test/java 目录下创建包 com.higanbana.user.controller

在包下创建测试类 TestController

1
2
3
4
5
6
7
8
9
10
11
12
package com.higanbana.user.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "Hello World!";
}
}

1707036964271.png