千家信息网

怎么使用IDEA创建SpringBoot项目

发表于:2024-10-28 作者:千家信息网编辑
千家信息网最后更新 2024年10月28日,本篇内容主要讲解"怎么使用IDEA创建SpringBoot项目",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"怎么使用IDEA创建SpringBoot项目"
千家信息网最后更新 2024年10月28日怎么使用IDEA创建SpringBoot项目

本篇内容主要讲解"怎么使用IDEA创建SpringBoot项目",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"怎么使用IDEA创建SpringBoot项目"吧!

1、在IDEA上新建一个Project,选择Spring Initializr,

Project SDK 选择安装的JDK;

Choose Initializr Service URL 选择默认(Default:https://start.spring.io )

选择项目模板

点击Next

2、进行项目配置

设置项目数组(group),项目标识(Artifact),Type选择一个Maven Project 表示是一个maven项目

Version:项目版本号

Name:项目名称

Description:项目描述

Package:项目包名

项目配置

点击Next 下一步

3、选择项目模板

我们来选择创建一个Web项目

选择Spring Boot版本

选择项目模板

4、设置项目名称和项目路径

设置项目名称和项目路径

设置完项目路径,和项目名称后,点击FInish,创建项目完成,需要进行项目构建,等一小会即可完成。

5、创建完成,我们删除.mvn文件夹,mvnw文件和 mvnw.cmd文件

删除文件

6、我们来看一下maven配置的pom.xml文件,里面包含了SpringBoot项目运行所需的版本库

pom.xml

SpringBoot运行所需库为:

      org.springframework.boot    spring-boot-starter-parent    2.0.1.RELEASE       
            org.springframework.boot      spring-boot-starter-web              org.springframework.boot      spring-boot-starter-test      test      

7、创建一个HelloService

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

8、创建HelloService的实现类HelloServiceImpl,实现sayHello()方法,返回"Hello World!"

package com.example.springbootdemo.service.impl;import com.example.springbootdemo.service.HelloService;import org.springframework.stereotype.Component;@Componentpublic class HelloServiceImpl implements HelloService { @Override public String sayHello() {   return "Hello World!"; }}

9、创建HelloController,调用HelloService实现类,打印"Hello World!"到浏览器

package com.example.springbootdemo.service.impl;import com.example.springbootdemo.service.HelloService;import org.springframework.stereotype.Component;@Componentpublic class HelloServiceImpl implements HelloService { @Override public String sayHello() {   return "Hello World!"; }}

10、见证奇迹的时刻,我们来运行一下所建项目,看能不能跟我们预期一样,在浏览器输入访问地址 http://localhost:8080/hello

就可以看到Hello World!

到此,相信大家对"怎么使用IDEA创建SpringBoot项目"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0