创建步骤(需要联网)
第一步:New - > Project
第二步:选择Spring Initializer
第三步:编写相关的包名
第四步:选择相应的需求模块
第五步:Finish
没有必要的文件可以删除
我们可以发现:默认生成的Spring Boot项目,主程序已经生成好了,我们只需要编写自己的逻辑。
resources文件夹中目录结构
运行测试
编写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