spring Boot 入门

1. 什么是SpringBoot

  Spring Boot Spring 开源组织下的子项目,是 Spring 组件一站式解决方案,主要是简化了使用 Spring 的难度,简省了繁重的配置,提供了各种启动器,开发者能快速上手。

2. SpringBoot的优缺点

  Spring Boot优点:

  独立运行:

  自动配置

  无代码生成和XML配置

  应用监控

  Spring Boot缺点

  虽然易上手,但如果不了解原理,遇到问题会比较棘手。

3.实现SpringBoot需要引用父类

  pom.xml 配置

   <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> </parent>
<dependencies>
<dependency>
<!--web功能的起步依赖-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.7.RELEASE</version>
</dependency>
</dependencies>

 

4.测试

package com.springBoot;

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,args);
}
}

 5.添加Controller测试

@RestController
public class SpringBootController {

    @RequestMapping("/quick")
    public String quick(){
        return "Hello SpringBoot";
    }
}

controller类必须和MySpringBootApplication在同一文件下

@RestController注解相当于@ResponseBody + @Controller合在一起的作用

@responsebody表示该方法的返回结果直接写入HTTP response body中
一般在异 步获取数据时使用,在使用@RequestMapping后,返回值通常解析为跳转路径,加上@responsebody后返回结果不会被解析为跳转路 径,

而是直接写入HTTP response body中。比如异步获取json数据,加上@responsebody后,会直接返回json数据。

 

原文地址:https://www.cnblogs.com/dragonyl/p/11435630.html