创建步骤(需要联网)

第一步:New - > Project

在这里插入图片描述

第二步:选择Spring Initializer

在这里插入图片描述

第三步:编写相关的包名

在这里插入图片描述

第四步:选择相应的需求模块

在这里插入图片描述

第五步:Finish

在这里插入图片描述

没有必要的文件可以删除

在这里插入图片描述

我们可以发现:默认生成的Spring Boot项目,主程序已经生成好了,我们只需要编写自己的逻辑。

resources文件夹中目录结构

文件夹说明
static保存所有的静态资源如 js css images
templates保存所有的模板页面;(Spring Boot默认jar包使用嵌入式的Tomcat,默认不支持JSP页 面)可以使用模板引擎(freemarker、thymeleaf)
application.propertiesSpring Boot应用的配置文件,可以修改一些默认设置

运行测试

编写controller

HelloController:

package com.keafmd.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Keafmd
 *
 * @ClassName: HelloController
 * @Description:
 * @author: 牛哄哄的柯南
 * @date: 2021-02-22 20:36
 */

/*@ResponseBody //这个类的所有的方法返回的数据直接写给浏览器(如果是对象还能转为json对象)
@Controller*/
@RestController  //等价于上面两个
public class HelloController {


    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!--quick";
    }
}

项目目录结构

在这里插入图片描述

启动主程序

在这里插入图片描述

运行结果

控制台输出:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.3)

2021-02-22 21:52:42.268  INFO 24532 --- [           main] s.SpringBoot01HelloworldQuickApplication : Starting SpringBoot01HelloworldQuickApplication using Java 1.8.0_181 on DESKTOP-JISCGLF with PID 24532 (F:\java_workspace\spring-boot-01-helloworld-quick\target\classes started by 章贺龙 in F:\java_workspace\spring-boot-01-helloworld-quick)
2021-02-22 21:52:42.271  INFO 24532 --- [           main] s.SpringBoot01HelloworldQuickApplication : No active profile set, falling back to default profiles: default
2021-02-22 21:52:47.963  INFO 24532 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-02-22 21:52:47.985  INFO 24532 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-22 21:52:47.985  INFO 24532 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-22 21:52:48.324  INFO 24532 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-22 21:52:48.324  INFO 24532 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5870 ms
2021-02-22 21:52:49.012  INFO 24532 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-22 21:52:50.745  INFO 24532 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-22 21:52:50.764  INFO 24532 --- [           main] s.SpringBoot01HelloworldQuickApplication : Started SpringBoot01HelloworldQuickApplication in 11.647 seconds (JVM running for 23.219)

访问http://localhost:8080/hello
在这里插入图片描述

以上就是IDEA使用Spring Initializer快速创建Spring Boot项目(超详细)的全部内容。

看完如果对你有帮助,感谢点赞支持!
如果你是电脑端的话,看到右下角的 “一键三连” 了吗,没错点它[哈哈]

在这里插入图片描述

加油!

共同努力!

Keafmd

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐