2024.12.6(SpringBoot知识点总结)

2.1.3 编写SpringBoot引导类
要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问

package com.itheima;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MySpringBootApplication {

public static void main(String[] args) {
    SpringApplication.run(MySpringBootApplication.class);
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
2.1.4 编写Controller
在引导类MySpringBootApplication同级包或者子级包中创建QuickStartController

package com.itheima.controller;

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

@Controller
public class QuickStartController {

@RequestMapping("/quick")
@ResponseBody
public String quick(){
    return "springboot 访问成功!";
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2.1.5 测试
执行SpringBoot起步类的主方法,控制台打印日志如下:

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

2018-05-08 14:29:59.714 INFO 5672 --- [ main] com.itheima.MySpringBootApplication : Starting MySpringBootApplication on DESKTOP-RRUNFUH with PID 5672 (C:\Users\muzimoo\IdeaProjects\IdeaTest\springboot_quick\target\classes started by muzimoo in C:\Users\muzimoo\IdeaProjects\IdeaTest)
... ... ...
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-05-08 14:30:03.126 INFO 5672 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-05-08 14:30:03.196 INFO 5672 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-05-08 14:30:03.206 INFO 5672 --- [ main] com.itheima.MySpringBootApplication : Started MySpringBootApplication in 4.252 seconds (JVM running for 5.583)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
通过日志发现,Tomcat started on port(s): 8080 (http) with context path ‘’

tomcat已经起步,端口监听8080,web应用的虚拟工程名称为空

打开浏览器访问url地址为:http://localhost:8080/quick(重点!!!!!!!!!!!!!)

posted @ 2025-01-10 23:36  ysd666  阅读(18)  评论(0)    收藏  举报