Spring Boot从入门到熟练-1.入门

tech2024-08-03  51

入门

一、创建maven项目二、引入Spring Boot1.引入库2.创建示例 三、测试结果总结


一、创建maven项目

填写相关id

二、引入Spring Boot

1.引入库

2.创建示例

代码如下:

package cn.lilinghui.sprintboottest.controller; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class Example { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Example.class, args); } }

这里需要注意的注解是RestController、EnableAutoConfiguration、RequestMapping RestController:表示该类是controller EnableAutoConfiguration:表示该应用开启自动配置功能 RequestMapping:表示该类的页面转向

三、测试结果

控制台输出

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.3.RELEASE) 2020-09-03 20:31:42.979 INFO 17200 --- [ main] c.l.sprintboottest.controller.Example : Starting Example on SCD0079 with PID 17200 (C:\Users\llh\workspace\sprintboottest\target\classes started by lilinghui in C:\Users\llh\workspace\sprintboottest) 2020-09-03 20:31:42.983 INFO 17200 --- [ main] c.l.sprintboottest.controller.Example : No active profile set, falling back to default profiles: default 2020-09-03 20:31:43.937 INFO 17200 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-09-03 20:31:43.950 INFO 17200 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-09-03 20:31:43.950 INFO 17200 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.37] 2020-09-03 20:31:44.044 INFO 17200 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-09-03 20:31:44.044 INFO 17200 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1013 ms 2020-09-03 20:31:44.253 INFO 17200 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-09-03 20:31:44.442 INFO 17200 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-09-03 20:31:44.452 INFO 17200 --- [ main] c.l.sprintboottest.controller.Example : Started Example in 1.87 seconds (JVM running for 2.27)

以下为输出页面


总结

以上就是今天要讲的内容,本文仅仅简单介绍了spring boot的入门使用,而spring boot提供了大量能使我们快速便捷地处理web的函数和方法。

最新回复(0)