1.需求
浏览器发送hello请求,服务器接受请求并处理,响应hello world字符串;

2.创建maven工程
这样做的目的是: 让其后创建的Project 都是默认的使用自己的Maven
(2)SpringBoot:创建第一个helloworld
导入自己的Maven配置
(2)SpringBoot:创建第一个helloworld
Maven的具体配置和下载详情请看:https://blog.csdn.net/Yuz_99/article/details/88927253
打开IDEA - 》 new - 》 project - 》 选择Maven - 》 选择好JDK -》 next - 》进入页面后选择 Enable Auto-Import(自动导入 在pom.xml文件里面写一个依赖 IDEA会自动导入依赖)
(2)SpringBoot:创建第一个helloworld
(2)SpringBoot:创建第一个helloworld
(2)SpringBoot:创建第一个helloworld
2.导入spring -boot 相关的依赖

	<!-- Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.3.RELEASE</version>
	</parent>

	<!-- Add typical dependencies for a web application -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<!-- Package as an executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

3.编写主程序:启动Spring Boot应用
在src - 》main-》java 下 创建一个类Java.class 名字为MainApplication
(2)SpringBoot:创建第一个helloworld
(2)SpringBoot:创建第一个helloworld
在主类上方写上,@SpringApplication (来标注这是一个主程序类,说明这是一个Spring Boot应用)
(2)SpringBoot:创建第一个helloworld
然后输入psvm
(2)SpringBoot:创建第一个helloworld
(2)SpringBoot:创建第一个helloworld

在里面写入
SpringApplication.run(类名.class,args);
(代表Spring应用启动起来)
此类为:SpringApplication.run(MainApplication.class,args);

(2)SpringBoot:创建第一个helloworld

4.编写相关的Controller,Service
在main.java.com.study下创建Java.class 名为 controller.helloController(意味着study下还有一个子包 包名controller 此包底下还有一个类 类名为helloController)

切记:Application 需要run的类要包含子类Controller
(2)SpringBoot:创建第一个helloworld
(2)SpringBoot:创建第一个helloworld
在上方下入 @Controller (处理请求)
(2)SpringBoot:创建第一个helloworld

浏览器会发送hello请求 标识一下@RequestMapping
(2)SpringBoot:创建第一个helloworld
把return的内容 写出去 把hello world写到浏览器 需要结合一个注解@ResponseBody
(2)SpringBoot:创建第一个helloworld
总体效果图为:
(2)SpringBoot:创建第一个helloworld

验证完成
(2)SpringBoot:创建第一个helloworld

如果报错:This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Mar 31 14:49:15 CST 2019 There was an unexpected error (type=Not Found, status=404). No message available
详情请看:https://blog.csdn.net/weixin_42205494/article/details/81330615 此博主内容!

相关文章:

  • 2022-12-23
  • 2021-06-10
  • 2021-07-18
  • 2021-08-14
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2022-01-12
  • 2022-01-05
  • 2022-01-22
  • 2021-07-19
  • 2022-12-23
  • 2021-11-23
  • 2021-12-31
相关资源
相似解决方案