02.Springboot入门

本文详细介绍如何使用SpringBoot创建一个简单的Web应用,包括pom文件中引入SpringBoot依赖、创建RESTful风格的控制器以及启动类的编写。通过示例代码,读者可以快速掌握SpringBoot的基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.pom引入springboot

<!-- Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	
	<dependencies>
		<!--核心模块,包括自动配置支持、日志和YAML -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<!-- 测试模块,包括JUnit、Hamcrest、Mockito -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- 引入Web模块,需添加spring-boot-starter-web模块: -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

2.

3.新建一个控制层

@RestController
public class HelloController {
	@RequestMapping("/hello")
	public String hello() {
		return "Hello Spring Boot!";
	}
	/**
	 *获取车牌列表
	 * @return
	 *//*
	@RequestMapping("/GetCarMessages")
	public String GetCarMessages() {
		return "Hello Spring Boot!";
	}
	
	*//**
	 *登录
	 * @return
	 *//*
	@RequestMapping("/Login")
	public String Login() {
		return "Hello Spring Boot!";
	}*/
	
	
}

4.启动类

@SpringBootApplication
public class MyApplication {
	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值