logo头像
Snippet 博客主题

1.Spring Boot 简介

1 创建项目

SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent

pom.xml
中 添加

1
2
3
4
5
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>

SpringBoot要集成SpringMVC进行Controller的开发,所以项目要导入web的启动依赖

1
2
3
4
5
6
<dependencies> 
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

MySpringBootApplication.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package cn.kylin;

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

/**
* Hello World!
*
*/
@SpringBootApplication
public class MySpringBootApplication {

public static void main(String[] args) {
System.out.println("启动 Spring Boot...");
SpringApplication.run(MySpringBootApplication.class, args);
}
}

QuickController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package cn.kylin.controller;

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


@Controller
public class QuickController {

@GetMapping("/hello")
@ResponseBody
public String hello() {
return "hello,world";
}
}

支付宝打赏 微信打赏

打赏