zoukankan      html  css  js  c++  java
  • 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数据。

     

  • 相关阅读:
    iOS 自带系统语音识别
    对iOS10新增Api的详细探究
    iOS 技术前瞻
    iOS 之 byte NSString NSData类型转换
    iOS 文本属性
    基本力
    xamarin mac 基础知识 之 界面
    xamarin mac 之 基础知识
    xamarin mac 之 资料
    I方法 thinkphp
  • 原文地址:https://www.cnblogs.com/dragonyl/p/11435630.html
Copyright © 2011-2022 走看看