首页 > 其他分享 >2024.12.6(SpringBoot知识点总结)

2024.12.6(SpringBoot知识点总结)

时间:2025-01-10 23:47:54浏览次数:1  
标签:2024.12 知识点 SpringBoot springframework MySpringBootApplication __ org 14

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(重点!!!!!!!!!!!!!)

标签:2024.12,知识点,SpringBoot,springframework,MySpringBootApplication,__,org,14
From: https://www.cnblogs.com/yangsongduo/p/18664923

相关文章

  • 2024.12.7(SpringBoot知识点总结)
    2.2.2SpringBoot代码解析@SpringBootApplication:标注SpringBoot的启动类,该注解具备多种功能(后面详细剖析)SpringApplication.run(MySpringBootApplication.class)代表运行SpringBoot的启动类,参数为SpringBoot启动类的字节码对象2.2.3SpringBoot工程热部署我们在开发中反复......
  • 2024.12.9(SpringBoot知识点总结)
    通过idea快速创建的SpringBoot项目的pom.xml中已经导入了我们选择的web的起步依赖的坐标4.0.0<groupId>com.itheima</groupId><artifactId>springboot_quick2</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name&g......
  • 2024.12.11(SpringBoot知识点总结)
    3.1.2分析spring-boot-starter-web按住Ctrl点击pom.xml中的spring-boot-starter-web,跳转到了spring-boot-starter-web的pom.xml,xml配置如下(只摘抄了部分重点配置):4.0.0org.springframework.bootspring-boot-starters2.0.1.RELEASEorg.springframework.bootspring-boot-s......
  • 2024.12.10(SpringBoot知识点总结)
    3.1起步依赖原理分析3.1.1分析spring-boot-starter-parent按住Ctrl点击pom.xml中的spring-boot-starter-parent,跳转到了spring-boot-starter-parent的pom.xml,xml配置如下(只摘抄了部分重点配置):org.springframework.bootspring-boot-dependencies2.0.1.RELEASE../../spring......
  • 2024.12.13(SpringBoot知识点总结)
    4.1SpringBoot配置文件类型4.1.1SpringBoot配置文件类型和作用SpringBoot是基于约定的,所以很多配置都有默认值,但如果想使用自己的配置替换默认配置的话,就可以使用application.properties或者application.yml(application.yaml)进行配置。SpringBoot默认会从Resources目录下加载......
  • 2024.12.12(SpringBoot知识点总结)
    3.2自动配置原理解析按住Ctrl点击查看启动类MySpringBootApplication上的注解@SpringBootApplication@SpringBootApplicationpublicclassMySpringBootApplication{publicstaticvoidmain(String[]args){SpringApplication.run(MySpringBootApplication.class);}}1......
  • 2024.12.15(SpringBoot知识点总结)
    4.1.2.2.2配置Map数据同上面的对象写法4.1.2.2.3配置数组(List、Set)数据语法:​key:​-value1​-value2或者:​key:[value1,value2]示例代码:city:beijingtianjinshanghaichongqing或者city:[beijing,tianjin,shanghai,chongqing]集合中的元素是对象形式......
  • 2024.12.16(SpringBoot知识点总结)
    4.2配置文件与配置类的属性映射方式4.2.1使用注解@Value映射我们可以通过@Value注解将配置文件中的值映射到一个Spring管理的Bean的字段上例如:application.properties配置如下:person:name:zhangsanage:18123或者,application.yml配置如下:person:name:zhangsanag......
  • 2024.11.25(使用SpringBoot实现增删改查)
    创建数据库和表首先,需要创建一个数据库和表,以便进行CRUD操作。例如,使用MySQL创建一个名为user的表,包含id,name,salary等字段。构建项目结构在IDEA中新建一个SpringBoot项目,选择合适的依赖,如SpringWeb,MyBatis,MySQLDriver等。项目通常包含以下结构:Controller层:处理H......
  • 2024.11.26(使用SpringBoot实现增删改查)
    示例代码以下是一个简单的UserController类示例,展示了如何使用SpringBoot进行CRUD操作:@RestController@RequestMapping("/user")publicclassUserController{@AutowiredprivateUserServiceuserService;@GetMapping("/{id}")publicUsergetUser(@PathVariableInteger......