IDEA使用Spring Initializer快速创建Spring Boot项目(超详细)

r囧r小猫 2022-10-31 13:40 508阅读 0赞

IDEA使用Spring Initializer快速创建Spring Boot项目(超详细)

  • 创建步骤(需要联网)
    • 第一步:New - > Project
    • 第二步:选择Spring Initializer
    • 第三步:编写相关的包名
    • 第四步:选择相应的需求模块
    • 第五步:Finish
    • 没有必要的文件可以删除
    • resources文件夹中目录结构
  • 运行测试
    • 编写controller
    • 项目目录结构
    • 启动主程序
    • 运行结果

创建步骤(需要联网)

第一步:New - > Project

在这里插入图片描述

第二步:选择Spring Initializer

在这里插入图片描述

第三步:编写相关的包名

在这里插入图片描述

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

在这里插入图片描述

第五步:Finish

在这里插入图片描述

没有必要的文件可以删除

在这里插入图片描述

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

resources文件夹中目录结构






















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

运行测试

编写controller

HelloController:

  1. package com.keafmd.springboot.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.ResponseBody;
  5. import org.springframework.web.bind.annotation.RestController;
  6. /** * Keafmd * * @ClassName: HelloController * @Description: * @author: 牛哄哄的柯南 * @date: 2021-02-22 20:36 */
  7. /*@ResponseBody //这个类的所有的方法返回的数据直接写给浏览器(如果是对象还能转为json对象) @Controller*/
  8. @RestController //等价于上面两个
  9. public class HelloController {
  10. @RequestMapping("/hello")
  11. public String hello(){
  12. return "Hello World!--quick";
  13. }
  14. }

项目目录结构

在这里插入图片描述

启动主程序

在这里插入图片描述

运行结果

控制台输出:

  1. . ____ _ __ _ _
  2. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  3. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  4. ' |____| .__|_| |_|_| |_\__, | / / / /
  5. =========|_|==============|___/=/_/_/_/
  6. :: Spring Boot :: (v2.4.3)
  7. 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)
  8. 2021-02-22 21:52:42.271 INFO 24532 --- [ main] s.SpringBoot01HelloworldQuickApplication : No active profile set, falling back to default profiles: default
  9. 2021-02-22 21:52:47.963 INFO 24532 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
  10. 2021-02-22 21:52:47.985 INFO 24532 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  11. 2021-02-22 21:52:47.985 INFO 24532 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
  12. 2021-02-22 21:52:48.324 INFO 24532 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  13. 2021-02-22 21:52:48.324 INFO 24532 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5870 ms
  14. 2021-02-22 21:52:49.012 INFO 24532 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
  15. 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 ''
  16. 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

发表评论

表情:
评论列表 (有 0 条评论,508人围观)

还没有评论,来说两句吧...

相关阅读