• springboot入门


    springboot是什么?
    Spring Boot 是所有基于 Spring 开发的项目的起点。Spring Boot 的设计是为了让你尽可能快的跑起来 Spring 应用程序并且尽可能减少你的配置文件。简单来说就是SpringBoot其实不是什么新的框架,它默认配置了很多框架的使用方式
    SpringBoot四个主要特性:

    1、SpringBoot Starter:他将常用的依赖分组进行了整合,将其合并到一个依赖中,这样就可以一次性添加到项目的Maven或Gradle构建中;

    2、自动配置:SpringBoot的自动配置特性利用了Spring4对条件化配置的支持,合理地推测应用所需的bean并自动化配置他们;

    3、命令行接口:(Command-line-interface, CLI):SpringBoot的CLI发挥了Groovy编程语言的优势,并结合自动配置进一步简化Spring应用的开发;

    4、Actuatir:它为SpringBoot应用的所有特性构建一个小型的应用程序。但首先,我们快速了解每项特性,更好的体验他们如何简化Spring编程模型

    springboot项目创建:
    在这里插入图片描述
    配置:
    如果没有jrebel就勾选spring boot devtools,他会实时更新你的代码
    在这里插入图片描述

    application.yml:

    server:
      port: 8080 #8080为访问端口,可以自己设置
    student:
      name: {k1: '2',k2: '3'}
      password: 1234
    
    • 1
    • 2
    • 3
    • 4
    • 5

    导入web依赖:

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

    controller:

    package com.xujie.springboot.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    /**
     * @author 许缘
     * @company xxx公司
     * @create 2022-11-12  9:51
     */
    @RestController
    public class TestController {
        @RequestMapping("/home")
        public String home(){
             return "yes";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    访问:localhost:8080/home
    在这里插入图片描述
    导入该依赖:

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    实体类:

    package com.xujie.springboot.pojo;
    
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Controller;
    
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    
    /**
     * @author 许缘
     * @company xxx公司
     * @create 2022-11-12  10:09
     */
    @Controller
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @ConfigurationProperties(prefix = "student")
    public class Student {
    
        //List,Set,Map,String
        private Map name;
        private String password;
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    测试得到yml文件中的学生数据:

    package com.xujie.springboot;
    
    import com.xujie.springboot.pojo.Student;
    import org.junit.jupiter.api.Test;
    import org.junit.jupiter.api.extension.ExtendWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit.jupiter.SpringExtension;
    
    @ExtendWith(SpringExtension.class)
    @SpringBootTest
    class Springboot02ApplicationTests {
        @Autowired
        private Student student;
        
        @Test
        void contextLoads() {
            System.out.println(student);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    ok,完成。

  • 相关阅读:
    【科技素养】蓝桥杯STEMA 科技素养组模拟练习试卷E
    数据分析三剑客之一:Numpy详解及实战
    AppInfo应用信息查看V1.0.2测试版
    背后的力量 | 搭建新型IT基础架构 华云数据助力妇幼保健院提升数字化医院建设水平
    【数据mock】大数据Mock商城数据
    QTday3
    数据结构基本概念-Java常用算法
    rqt_publisher报错/publisher_widget.py“, line 105, in _update_thread_run
    FFmpeg v4l2m2m的capture和output
    mmap 创建共享内存映射
  • 原文地址:https://blog.csdn.net/weixin_63719049/article/details/127818087