首页 > 其他分享 >Spring Boot学习日记9

Spring Boot学习日记9

时间:2024-02-29 16:36:34浏览次数:23  
标签:Spring Boot private example springframework import org com 日记

在springboot项目中的resources目录下新建一个文件 application.yml

编写一个实体类 Dog;

package com.example.springboot02configure.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
//添加到spring组件中
public class Dog {
    private String name;
    private Integer age;
}

编写一个person类

package com.example.springboot02configure.pojo;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
@ConfigurationProperties(prefix = "person")
public class Person {

    private String name;
    private Integer age;
    private Boolean happy;
    private Date birth;
    private Map<String,Object> maps;
    private List<Object> lists;
    private Dog dog;

}

在yaml中写入对象

Person:
  name: xiaoqi
  age: 13
  happy: false
  birth: 2009/01/15
  maps: {k1: v1,k2: v2}
  lists:
    - code
    - dog
  dog:
    name: qq
    age: 1

在测试程序中测试

package com.example.springboot02configure;

import com.example.springboot02configure.pojo.Dog;
import com.example.springboot02configure.pojo.Person;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.swing.*;

@SpringBootTest
class SpringBoot02ConfigureApplicationTests {
    @Autowired
    private Person person;


    @Test
    void contextLoads() {
        System.out.println(person);
    }

}

 

标签:Spring,Boot,private,example,springframework,import,org,com,日记
From: https://www.cnblogs.com/bzsc/p/18044652

相关文章

  • Spring Boot学习日记6
    @SpringBootConfiguration:SpringBoot的配置@Configuration:spring配置类@Component:说明这也是一个spring的组件@EnableAutoConfiguration:自动配置@AutoConfigurationPackage:自动配置包@Import({Registrar.class}):导入了选择器@Import({AutoConfigurationImportSelect......
  • Spring Boot学习日记7
    学会了配置springboot导入各种组件SpringBoot在启动的时候,从类路径下/META-INF/spring.factories获取指定的值将这些自动配置的类导入容器,自动配置类就会生效,帮我们进行自动配置以前我们需要自动配置的东西,现在不需要了整合javaEE,解决方案和自动配置的东西都在Spring-boot-......
  • How to Create a Wimboot Installation of Windows 8.1(转载)
    HowtoCreateaWimbootInstallationofWindows8.1Introduction:HowtoCreateaWimbootInstallationofWindows8.1IntroductionEverwonderhowcomputermanufacturerscanfita20GBinstallationofWindowsontoa16GBdrive?Itisnowpossiblewith......
  • 二月十三日安卓开发日记6
    1.获取SSHkeys输入 cd~/.ssh,返回"nosuchfileordirectory"表明电脑没有sshkey,需要创建sshkey。然后输入 ssh-keygen-trsa-C“git账号” 以下截图就证明成功了,这个时候按照它给的打开以下地址: 按路径进入.ssh,里面存储的是两个sshkey的秘钥,id_rsa.pub文件里......
  • 二月十四日安卓开发日记7
    提交代码如果我们本地的代码有了更新,为了保持本地与远程的代码同步,我们就需要把本地的代码推到远程的仓库,代码示例:gitpushoriginmaster如果我们远程仓库的代码有了更新,同样为了保持本地与远程的代码同步,我们就需要把远程的代码拉到本地,代码示例:gitpulloriginmaster下面就......
  • 二月十八日安卓开发日记8
    测试创建一个任意格式,任意名称的文件然后同样在这个文件夹里面右键gitbash进黑框框,gitadd我们新增的文件 输入然后gitcommit-m“测试是否成功” 引号内的内容可以随意改动 输入push指令 gitpushoriginmain  打开GitHub,看到刚刚上传的文件,显示成功。......
  • 二月五日安卓开发日记1
    1.GitHub打开:第一种:GitHub:Let’sbuildfromhere·GitHub打开网页版主页(新手使用)             第二种:桌面版注册(长期使用)2.注册账号 右上角signup注册 输入邮箱 登录进入一下界面......
  • 二月七日安卓开发日记3
    gitbash下载与安装Gitbash下载地址:https://git-scm.com/进入官网downloads下载进入以下界面有Mac,Windows,Linux版本 选择windows 等待下载......
  • 三分钟数据持久化:Spring Boot, JPA 与 SQLite 的完美融合
    三分钟,迎接一个更加高效和简便的开发体验。在快节奏的软件开发领域,每一个简化工作流程的机会都不容错过。想要一个无需繁琐配置、能够迅速启动的数据持久化方案吗?这篇文章将是你的首选攻略。在这里,我们将向你展示如何将SpringBoot的便捷性、JPA的强大查询能力和SQLite的......
  • 二月八日安卓开发日记4
     安装直接next 图中的两个选择,则分别表示 打开GitBash 和 浏览Git版本信息选择LaunchGitBash,进入如下界面......