怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目-創(chuàng)新互聯(lián)

本篇內(nèi)容主要講解“怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目”吧!

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的鐵門關(guān)網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

1、在IDEA上新建一個(gè)Project,選擇Spring Initializr,

Project SDK 選擇安裝的JDK;

Choose Initializr Service URL 選擇默認(rèn)(Default:https://start.spring.io )

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

選擇項(xiàng)目模板

點(diǎn)擊Next

2、進(jìn)行項(xiàng)目配置

設(shè)置項(xiàng)目數(shù)組(group),項(xiàng)目標(biāo)識(shí)(Artifact),Type選擇一個(gè)Maven Project 表示是一個(gè)maven項(xiàng)目

Version:項(xiàng)目版本號(hào)

Name:項(xiàng)目名稱

Description:項(xiàng)目描述

Package:項(xiàng)目包名

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

項(xiàng)目配置

點(diǎn)擊Next 下一步

3、選擇項(xiàng)目模板

我們來選擇創(chuàng)建一個(gè)Web項(xiàng)目

選擇Spring Boot版本

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

選擇項(xiàng)目模板

4、設(shè)置項(xiàng)目名稱和項(xiàng)目路徑

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

設(shè)置項(xiàng)目名稱和項(xiàng)目路徑

設(shè)置完項(xiàng)目路徑,和項(xiàng)目名稱后,點(diǎn)擊FInish,創(chuàng)建項(xiàng)目完成,需要進(jìn)行項(xiàng)目構(gòu)建,等一小會(huì)即可完成。

5、創(chuàng)建完成,我們刪除.mvn文件夾,mvnw文件和 mvnw.cmd文件

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

刪除文件

6、我們來看一下maven配置的pom.xml文件,里面包含了SpringBoot項(xiàng)目運(yùn)行所需的版本庫

怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目

pom.xml

SpringBoot運(yùn)行所需庫為:

<!-- SpringBoot項(xiàng)目的基礎(chǔ)庫文件-->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
<!-- SpringBoot項(xiàng)目的基礎(chǔ)庫文件-->
  <dependencies>
<!-- web項(xiàng)目庫-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
<!-- 測(cè)試所需庫-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

7、創(chuàng)建一個(gè)HelloService

package com.example.springbootdemo.service;
import org.springframework.stereotype.Service;
@Service
public interface HelloService {
  String sayHello();
}

8、創(chuàng)建HelloService的實(shí)現(xiàn)類HelloServiceImpl,實(shí)現(xiàn)sayHello()方法,返回"Hello World!"

package com.example.springbootdemo.service.impl;
import com.example.springbootdemo.service.HelloService;
import org.springframework.stereotype.Component;

@Component
public class HelloServiceImpl implements HelloService {
 @Override
 public String sayHello() {
   return "Hello World!";
 }
}

9、創(chuàng)建HelloController,調(diào)用HelloService實(shí)現(xiàn)類,打印"Hello World!"到瀏覽器

package com.example.springbootdemo.service.impl;
import com.example.springbootdemo.service.HelloService;
import org.springframework.stereotype.Component;

@Component
public class HelloServiceImpl implements HelloService {
 @Override
 public String sayHello() {
   return "Hello World!";
 }
}

10、見證奇跡的時(shí)刻,我們來運(yùn)行一下所建項(xiàng)目,看能不能跟我們預(yù)期一樣,在瀏覽器輸入訪問地址 http://localhost:8080/hello

就可以看到Hello World!

到此,相信大家對(duì)“怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

網(wǎng)站名稱:怎么使用IDEA創(chuàng)建SpringBoot項(xiàng)目-創(chuàng)新互聯(lián)
URL分享:http://muchs.cn/article28/cshecp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、軟件開發(fā)網(wǎng)頁設(shè)計(jì)公司、品牌網(wǎng)站建設(shè)網(wǎng)站排名、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)