1. فتح الفكرة ، وإنشاء مشروع جديد ، واختر Spring initializr
2. أدخل قطعة أثرية
3. تحقق من الويب
4. انقر فوق إنهاء
5. أدخل المشروع وحذف المحتوى التالي
ملف pom.xml:
<؟ XSI: schemalocation = "http://maven.apache.org/pom/4.0.0 <soph> 0.0.1-snapshot </version> <packaging> جرة </packaging> <name> springbootdemo </name> <description> مشروع تجريبي لـ Spring Boot </description> <!-ابدأ التبعيات-> <NorpAnt> <roupiD> org.springframework.boot </groupid> <soph> 1.5.2.release </version> <repiledpath/> <!-بحث عن الأصل من المستودع-> </parent> <ferties> <project.build.sourceencoding> utf-8 </project.build.sourceencoding> <project.reporting.utputencoding> utf-8 </puropting. <Java.version> 1.8 </java.version> </sprenties> <ependencies> <!-تطوير تبعيات متعلقة بالمشروع على شبكة الإنترنت-> <Rependency> <roupiD> org.springframework.boot </rougiD> <SpringBoot> spring-boot-boot-web-web </artimactid> </expency. <roupl> org.springframework.boot </groupId> <StifactId> Spring-boot-starter-test </artifactid> <scope> test </scope> </reperence> </sependencies> <!-maven-build-> build> <clupin> <nuperid> <StifactId> Spring-Boot-Maven-Plugin </stifactid> </sultwing> </sults> </build> </project>
6. إنشاء Hellocontroller
حزمة com.example ؛ استيراد org.springframework.web.bind.annotation.requestmapping ؛ استيراد org.springframework.web.bind.annotation.restController ؛ RestController Public Class HelloconTroller {REquestMapping ("/hello") السلسلة العامة Hello () {return "Hello ، هذا عرض Springboot" ؛ }}7. سيكون لبرنامج SpringBootDemOapplication الذي تم إنشاؤه تلقائيًا بواسطة البرنامج تعليقًا على springbootapplication. يتم استخدام هذا التعليق التوضيحي للإشارة إلى أن هذه الفئة هي إدخال البرنامج.
حزمة com.example ؛ استيراد org.springframework.boot.springapplication ؛ استيراد org.springframework.boot.autoconfigure.SpringBootApplication ؛ // enter@SpringBootApplication الفئة العامة springbootdemoapplication {public static void main (string [] args) {springapplication.run (springbootdemoapplication.class ، args) ؛ }}يتيح SPRINGBOOTAPPLACITY مسح مكونات Spring ووظائف التكوين التلقائي لـ Springboot ، وهو ما يعادل الجمع بين التعليقات التوضيحية الثلاثة التالية معًا
(1) Configuration: اسم الجدول يستخدم هذا الفئة التكوين المستند إلى Java ، ويستخدم هذه الفئة كفئة تكوين
(2) componentscan: تمكين مسح التعليق التوضيحي
(3) enabeautoconfiguration: قم بتشغيل وظيفة التكوين التلقائي لـ Springboot
8. Run SpringbootDemPlication Class
امتحان:
أدخل http: // localhost: 8080/hello في شريط العناوين
9. ابدأ في استخدام طريقة بدء حزمة الجرة
(1) أولاً أدخل الدليل حيث يوجد المشروع. إذا كان نظام Mac ، انقر بزر الماوس الأيمن على المشروع ، وحدد الكشف في Finder ، وانقر بزر الماوس الأيمن على نظام Windows واختر العرض في Explorer في المشروع ، يمكنك فتح الدليل الذي يوجد فيه المشروع.
(2) افتح المحطة وأدخل الدليل الذي يوجد فيه المشروع
cd /Users/shanml/IdeaProjects/SpringbootDemo
أدخل تثبيت MVN لإنشاء المشروع
(3) بعد نجاح البناء ، سيكون هناك حزمة جرة إضافية في المجلد المستهدف للمشروع.
(4) استخدم java -jar springbootdemo-0.0.1-snapshot.jar
فقط ابدأ حزمة الجرة
الرجوع إلى:
الأخ الأكبر لياو: تعلم سبرينغ بوت في ساعتين
ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.