1.创建java类
2.编写
package com.itheima.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class hellp {
@RequestMapping("/hello")
public String hello(){
return "hello world";
}
}
3.运行
package要对应,如果要新建package,记得检查。
4.结果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.3.4)
2024-10-07T13:01:56.867+08:00 INFO 15612 --- [demo] [ main] com.itheima.demo.DemoApplication : Starting DemoApplication using Java 17.0.12 with PID 15612 (C:\springprogram\p2\demo\target\classes started by 25511 in C:\springprogram\p2)
2024-10-07T13:01:56.873+08:00 INFO 15612 --- [demo] [ main] com.itheima.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2024-10-07T13:01:58.374+08:00 INFO 15612 --- [demo] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-10-07T13:01:58.396+08:00 INFO 15612 --- [demo] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-10-07T13:01:58.396+08:00 INFO 15612 --- [demo] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.30]
2024-10-07T13:01:58.495+08:00 INFO 15612 --- [demo] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-10-07T13:01:58.496+08:00 INFO 15612 --- [demo] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1511 ms
2024-10-07T13:01:58.972+08:00 INFO 15612 --- [demo] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2024-10-07T13:01:58.981+08:00 INFO 15612 --- [demo] [ main] com.itheima.demo.DemoApplication : Started DemoApplication in 2.915 seconds (process running for 4.589)
2024-10-07T13:07:20.313+08:00 INFO 15612 --- [demo] [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2024-10-07T13:07:20.329+08:00 INFO 15612 --- [demo] [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-10-07T13:07:20.391+08:00 INFO 15612 --- [demo] [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 62 ms
Spring Boot:显示是Spring工程,版本号3.3.4
Tomcat initialized with port 8080 (http):tomcat自动启动,绑定的端口号是8080.
测试:网页输入http://localhost:8080/hello