前に書く
周囲
win10(其他应该也可),
idea2020-2(最好保持一致),
jdk8+,
maven3.5.4(最好保持一致)
その他
部分的な依存によりダウンロードできない場合があるため、回避ソフトウェアを準備することをお勧めします。
1:ソースコードをダウンロードする
ここから自分のウェアハウスにコードをフォークします。フォークの目的は、ソースコードを直接変更することです。gitからのコードのダウンロードが遅すぎる場合は、コードをgitlabにインポートしてからダウンロードすることもできます。gitlabにインポートするおおよそのプロセスについては、次の図を参照してください。
完了後、git clone
コーディングできます。
2:コンパイル
2.1:ブランチを切り替える
ここではtag:v2.1.14.RELEASE
、コマンド形式を操作するために使用しますgit checkout -b <自定义本地分支名称> <远程分支名称>
。次のコマンドは、対応するブランチをローカルに作成します
git checkout -b v2.1.14.RELEASE-local v2.1.14.RELEASE
。
2.2:maven3.5.4を構成します
次のように、主にAliソースを追加します。
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
2.3:依存関係をダウンロードする
/paht/to/your3.5.4/mvn clean install -DskipTests -Pfast
失敗した場合は、さらに数回試してみてください。成功する前に何度か試してみました。あなたが見る最後のBUILD SUCCESS
ものは成功です。
2.4:フォーマットの問題を解決する
/paht/to/your3.5.4/mvn spring-javaformat:apply
このステップでは問題は発生しませんでした。問題が発生した場合は、さらに数回試行します。
2.5:アイデアプロジェクトに変換する
/paht/to/your3.5.4/mvn idea:idea
2.6:アイデアへのインポート
プロジェクトを選択してインポートするだけです。検証が成功したかどうかは、org.springframework.boot.tests.hibernate52.Hibernate52Application
クラスを実行することで検証できます。実行が成功すると、インポートが完了します。
2.7:フォーマット検出をオフにします
次のコンテンツをルートpom.xmlに追加します。
<properties>
<revision>2.1.14.RELEASE</revision>
<main.basedir>${basedir}</main.basedir>
<disable.checks>true</disable.checks> // 新添加的
</properties>
最終的なアイデアの効果は次のとおりです。
3:MVCプロジェクトを作成する
プロジェクトは、その中にspring-boot-tests
サブモジュールを作成することによって実行されます。
3.1:pomプロジェクトを作成するspring-boot-dongshidaddy-tests
次の図に示すように、マウスspring-boot-tests
でnew-module
選択し、選択maven
に注意して
ください。作成後に削除しsrc
、pom.xmlファイルのみを保持します。結局、私のpom.xmlは次のようになります。これは、入力されたgav情報が同じではないため、参考のために、まったく同じではない可能性があるためです。
<?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>
<artifactId>spring-boot-dongshidaddy-tests</artifactId>
<groupId>org.springframework.boot</groupId>
<!-- <version>2.1.14.RELEASE</version>-->
<version>${revision}</version>
<!-- <relativePath>../../pom.xml</relativePath>-->
</parent>
<artifactId>spring-boot-dongshidaddy-mvc-tests</artifactId>
<name>Spring Boot Yunai DONGSHIDADDY tests</name>
<description>测试springboot源码导入项目</description>
<properties>
<main.basedir>${basedir}/../../..</main.basedir>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.2:pomプロジェクトを作成するspring-boot-dongshidaddy-tests
方法は同じですが、spring-boot-dongshidaddy-tests
それを維持するように注意してくださいsrc
。最終的な画像は次のとおりです
。pomは次のとおりです。
<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>
<artifactId>spring-boot-dongshidaddy-tests</artifactId>
<groupId>org.springframework.boot</groupId>
<!-- <version>2.1.14.RELEASE</version>-->
<version>${revision}</version>
<!-- <relativePath>../../pom.xml</relativePath>-->
</parent>
<artifactId>spring-boot-dongshidaddy-mvc-tests</artifactId>
<name>Spring Boot Yunai DONGSHIDADDY tests</name>
<description>测试springboot源码导入项目</description>
<properties>
<main.basedir>${basedir}/../../..</main.basedir>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.3:メインのスタートアップクラスを作成する
@SpringBootApplication
public class MyMvcApplication {
public static void main(String[] args) {
SpringApplication.run(MyMvcApplication.class, args);
}
}
3.4:コントローラーを作成する
@Controller
@RequestMapping("/mydemo")
public class MyDemoController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "hi from dongshidaddy!";
}
}
3.5:テストを開始します
$ curl --silent http://localhost:8080/mydemo/hello
hi from dongshidaddy!