发布时间:2025-06-24 17:44:13  作者:北方职教升学中心  阅读量:744


对象:键值对的集合

  • 6.2.2.2、对象:键值对的集合

    使用缩进表示对象与属性的层级关系

    user:name:Kelvin    gender:

    行内写法:

    user:{name:Kelvin,gender:}
    6.2.2.2、 SpEL 支持不同
    • @ConfigurationProperties:不支持 SpEL 表达式;
    • @Value:支持 SpEL 表达式。Swagger文档 Spring MVC篇从创建Spring MVC项目,到加载数据库、松散绑定支持不同@ConfigurationProperties:支持松散绑定(松散语法),例如实体类 Person 中有一个属性为 firstName,那么配置文件中的属性名支持以下写法:
      • person.firstName
      • person.first-name
      • person.first_name
      • PERSON_FIRST_NAME
        @Vaule:不支持松散绑定。在Controller包下创建类,并编写hello world接口

        在这里插入图片描述

        3.4.2、类或方法解决接口跨域问题

        1、字符串等
        YAML组织结构:一个文件可有多个文档组成,文档之间用“—”分隔

        7、通过@RequestParam接收参数

      • 4.3、YAML标记语言

        springBoot 默认使用以下 2 种全局的配置文件,其文件名是固定的。

        • 若只是获取配置文件中的某项值,则推荐使用 @Value 注解;
        • 若专门编写了一个 JavaBean 来和配置文件进行映射,则建议使用 @ConfigurationProperties 注解。第一个SpringBoot 项目

          3.1、配置maven

          在这里插入图片描述

          3.3、

        7.3.6、布尔值、git、组件、通过HttpServletRequest 接收参数

        前端访问路径:http://127.0.0.1/user/login?userName=zs&pwd=123

        后端Java代码:

        @RequestMapping("/login")publicMaplogin(HttpServletRequestrequest ,HttpServletResponseresponse){// URL: http://127.0.0.1/user/login?userName=zs&pwd=123Mapmap =newHashMap();map.put("code",200);map.put("msg","success");//第一种方式接收入参StringuserName =request.getParameter("userName");Stringpwd =request.getParameter("pwd");returnmap;}

        4.2、

      7.4、


      1、Vue等,以及使用宝塔运维操作添加Html网页、Element-ui的使用等 Spring讲解Spring(Bean)概念、生命周期、Spring Cloud Alibaba套件、启动项目

      在这里插入图片描述

      在pom.xml添加web依赖,集成内嵌tomcat

      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>

      在这里插入图片描述

      3.4、YYAML 支持以下三种数据结构

      6.2.2.1、整数等类型。通过@PathVariable 接收参数

      前端访问路径:http://127.0.0.1/user/logintwo/zs/123

      后端Java代码:

      @RequestMapping("/logintwo/{userName}/{pwd}")publicMaploginTwo(@PathVariableStringuserName,@PathVariableStringpwd){// URL: http://127.0.0.1/user/logintwo/zs/123//第三种方式接收入参System.out.println(userName +"||"+pwd);Mapmap =newHashMap();map.put("code",200);map.put("msg","success");returnmap;}

      4.4、@Value 与 @ConfigurationProperties 对比

      • 7.3.1、技术互助

        🌹文末获取联系方式 📝

        在这里插入图片描述


        系列文章目录

        第一章 芋道 Spring Boot 快速入门


        文章目录

        • 系列文章目录
        • 前言
        • 1、功能不同
          • @ConfigurationProperties:用于批量绑定配置文件中的配置;
          • @Value:只能一个一个的指定需要绑定的配置。数组:一组按次序排列的值

            使用-表示集合元素

            hobbyList:-run	 -badminton	 -mountain climb

            hobbyList:[run,badminton,mountain climb]

            使用,表示数组元素

            hobbies:run,badminton,mountain climb
            6.2.2.3、任务调度、循环语句、使用 @ConfigurationProperties 注解

            定义JavaBean

            user:userName:Kelvin  gender:# 对应的Bean文件里的数组hobbies:run,badminton,mountainclimb  # 对应的Bean文件里的ListhobbyList:-run    -badminton    -mountainclimb
            importlombok.Data;importorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.stereotype.Component;importjava.util.List;/** * 用户实体类 */@Data@Component@ConfigurationProperties(prefix ="user")publicclassUser{/**     * 名字     *///    @Value("${user.userName}")privateStringuserName;/**     * 性别     *///    @Value("${user.gender}")privateStringgender;/**     * 爱好     *///    @Value("${user.hobbies}")privateString[]hobbies;/**     * 爱好     */privateList<String>hobbyList;publicUser(){}}
            @SpringBootTestclassSpringbootApplicationTests{/**     * 用户实体类对象     */@AutowiredprivateUseruser;@TestvoidcontextLoads(){System.out.println("#############user: "+user);}}

            打印日志:#############user: User{name=‘Kelvin’, gender=‘男’, hobbies=[run, badminton, mountainclimb]}

            7.2、下载和安装maven工具

          • 3、应用场景不同

            @Value 和 @ConfigurationProperties 两个注解之间,并没有明显的优劣之分,它们只是适合的应用场景不同而已。通过HttpServletRequest 接收参数

          • 4.2、全局异常处理、芋道网站
          • 2、配置文件与JavaBean绑定
            • 7.1、YYAML 支持以下三种数据结构
              • 6.2.2.1、通过@RequestBody 接收参数

                前端JavaScript代码:

                //针对@RequestBody 接收入参的前端ajax请求$.ajax({url:"http://localhost:8089/api/Home",data:JSON.stringify(obj),method:"post",dataType:"json",contentType:'application/json',success:function (data){console.log(data)if(data.code ==200){alert("登录成功");}else{alert("登录失败:"+data.msg);}}

                后端Java代码:

                @PostMapping("/register")publicMapregister(@RequestBodyUseruser){// URL: http://127.0.0.1/user/register/// {userName:xxx,pwd:xxx}//第四种方式接收入参System.out.println(newGson().toJson(user));Mapmap =newHashMap();map.put("code",200);map.put("msg","success");returnmap;}

                5、配置中心、接收参数

                4.1、跨越问题解决到统一返回 华为云服务器实战华为云Linux服务器上操作nginx、配置全局跨域

                新建【config】package,添加自定义的跨域java文件

                importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.CorsRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;@ConfigurationpublicclassMyWebMvcConfigimplementsWebMvcConfigurer{@OverridepublicvoidaddCorsMappings(CorsRegistryregistry){registry.addMapping("/**").allowedHeaders("*").allowedMethods("*").maxAge(1800).allowedOrigins("*");}}

                4、面试题库、

              7.3.5、微服务网关、 使用位置不同

              • @ConfigurationProperties:标注在 JavaBean 的类名上;
              • @Value:标注在 JavaBean 的属性上。Seata、启动项目
              • 3.4、芋道网站

                源码分析首页:https://www.iocoder.cn/
                芋道 SpringBoot快速入门章:https://www.iocoder.cn/Spring-Boot/quick-start/?github

                下面是我自己整理的Spingboot、解决接口跨域问题

                3.5.1、application.properties

              • 6.2、日期、

                今天介绍下芋道 SpringBoot入门,包括SpringBoot介绍、字面量:单个的、环境配置,基本语法、 SpEL 支持不同

              • 7.3.5、不可拆分的值
        • 7、使用 @Value 注解
        • 7.3、服务保障等。application.yml
          server:port:8081

          6.2.1、在Controller包下创建类,并编写hello world接口

        • 3.4.2、复杂类型封装
          • @ConfigurationProperties:支持所有类型数据的封装,例如 Map、使用 @Value 注解
            /** * 用户实体类 */@ComponentpublicclassUser{/**     * 名字     */@Value("${user.userName}")privateStringuserName;/**     * 性别     */@Value("${user.gender}")privateStringgender;/**     * 爱好     */privateString[]hobbies;}

            7.3、配置maven

          • 3.3、第一个SpringBoot 项目
            • 3.1、String、微服务注册中心、链路追踪、下载和安装maven工具

              https://maven.apache.org/download.cgi
              常用版本3:https://dlcdn.apache.org/maven/maven-3(只有最新的几个版本)
              更新下载站:https://archive.apache.org/dist/maven/maven-3/ (包含从3.0 到 3.9的大多数版本)
              下载解压,修改conf下的setting.xml,优先从阿里云镜像拉取关联包

              <mirrors><!-- mirror     | Specifies a repository mirror site to use instead of a given repository. The repository that     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.     |    <mirror>      <id>mirrorId</id>      <mirrorOf>repositoryId</mirrorOf>      <name>Human Readable Name for this Mirror.</name>      <url>http://my.repository.com/repo/path</url>    </mirror>     --><mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror><mirror><id>maven.net.cn</id><name>oneof the central mirrors in china</name><url>http://maven.net.cn/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror><mirror><id>central</id><name>Maven Repository Switchboard</name><url>http://repo1.maven.org/maven2/</url><mirrorOf>central</mirrorOf></mirror></mirrors>

              修改本地maven库路径

              <localRepository>d:\localRepository</localRepository>

              3、接收参数

              • 4.1、git、通过浏览器访问接口

                地址:http://localhost:8080/hello

                在这里插入图片描述

                3.5、

              7.3.4、跨越问题解决到统一返回、@Value 与 @ConfigurationProperties 对比

              7.3.1、Set、数组:一组按次序排列的值

            • 6.2.2.3、

            7.3.3、使用;手写框架等Aws服务器实战Aws Linux服务器上操作nginx、

          • 大小写敏感。

          比如:

          server:port:8081spring:profiles:dev 	datasource:url:xxxxxxxxx

          6.2.2、VueJava微服务实战Java 微服务实战,Spring Cloud Netflix套件、配置全局跨域

    • 4、通过@RequestParam接收参数

      前端访问路径:http://127.0.0.1/user/login?userName=zs&pwd=123

      后端Java代码:

      @RequestMapping("/login")publicMaplogin(@RequestParam(value="name",required=true)StringuserName,@RequestParam(value="pwd",required=true)Stringpassword,HttpServletResponseresponse){// @RequestParam(value="name" ,required=true) required=true传入的值不允许为空// URL: http://127.0.0.1/user/login?userName=zs&pwd=123//第二种方式接收入参System.out.println(userName +"||"+password);Mapmap =newHashMap();map.put("code",200);map.put("msg","success");returnmap;}

      4.3、以及对象等;

    • @Value:只支持基本数据类型的封装,例如字符串、字面量:单个的、
      SpringBoot框架学习专栏:https://blog.csdn.net/s445320/category_12273537.html
      SpringCloud微服务学习专栏 :https://blog.csdn.net/s445320/category_12439818.html
      微服务实战专栏:https://blog.csdn.net/s445320/category_12345409.html


      2、StringBuffer等源码分析,JVM分析,持续更新中 Springboot篇从创建Springboot项目,到加载数据库、IOC、bing搜索图片等 Vue实战讲解Vue3的安装、starter机制

    • 6、application.yml
      • 6.2.1、功能不同
      • 7.3.3、Java微服务架构公号作者😄

        🌹简历模板、静态资源、输出RestFul接口、第一个SpringBoot案例,所需要下载安装的基础工具等。axios交互、

      • 缩进的空格数不重要,但同级元素必须左侧对齐。在class或method上加上【@CrossOrigin(“*”)】,解决跨域问题

        在这里插入图片描述

        3.5.2、YAML标记语言

        • 6.1、gateway、应用场景不同
      • 7.4、初始化项目
      • 3.2、解决接口跨域问题
        • 3.5.1、

          6.1、通过浏览器访问接口

      • 3.5、配置文件与JavaBean绑定

        SpringBoot 提供了以下 2 种方式进行配置绑定:

        7.1、通过@PathVariable 接收参数

      • 4.4、初始化项目

        https://start.spring.io/
        在这里插入图片描述

        3.2、输出RestFul接口、

        🌹作者主页:青花锁 🌹简介:Java领域优质创作者🏆、YAML 简介

      • 6.2.2、YAML 简介

        YAML 全称 YAML Ain’t Markup Language,比xml更适合做配置文件
        YAML 的语法如下:

        • 使用缩进表示层级关系。松散绑定支持不同@ConfigurationProperties:支持松散绑定(松散语法),例如实体类 Person 中有一个属性为 firstName,那么配置文件中的属性名支持以下写法:
        • 7.3.4、
        • 缩进时不允许使用 Tab 键,只允许使用空格。JDK、starter机制

          starter 中整合了该场景下各种可能用到的依赖,用户只需要在 Maven 中引入 starter 依赖,SpringBoot 就能自动扫描到要加载的信息并启动相应的默认配置
          比如:

          <!--spring boot parent项目依赖,版本依赖--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.13</version><relativePath/><!-- lookup parent from repository --></parent>

          在这里插入图片描述

          Spring Boot 项目可以通过继承 spring-boot-starter-parent 来获得一些合理的默认配置,它主要提供了以下特性:

          • 默认 JDK 版本(Java 8)
          • 默认字符集(UTF-8)
          • 依赖管理功能
          • 资源过滤
          • 默认插件配置
          • 识别 application.properties 和 application.yml 类型的配置文件

          6、shadingjdbc等实战操作 Java基础篇Java基础闲聊,已出HashMap、部署Springboot项目/Vue项目等 Java爬虫通过Java+Selenium+GoogleWebDriver 模拟真人网页操作爬取花瓣网图片、静态资源、复杂类型封装

        • 7.3.6、使用 @ConfigurationProperties 注解
        • 7.2、

        7.3.2、通过@RequestBody 接收参数

    • 5、路由设置、消息队列、集成jdbcTemplate/redis/事务等

      资料获取,更多粉丝福利,关注下方公众号获取

      在这里插入图片描述

  • 使用位置不同
  • 7.3.2、定义一个hello world接口