SpringBoot配置yaml,properties配置⽂件值获取(数组,对
象,Map)。。。
Person:
package com.atguigu.springboot.pojo;
import org.t.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Classname Person
*/
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private Integer age;
private Boolean stage;
private Date birth;
web设备是什么意思
private Map<String,Object> maps;
private List<Object> lists;
private Child child;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
一些好玩的编程代码public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Boolean getStage() {
return stage;
}
public void setStage(Boolean stage) {
this.stage = stage;
}
public Date getBirth() {
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Map<String, Object> getMaps() {
return maps;
}
public void setMaps(Map<String, Object> maps) {        this.maps = maps;
}
public List<Object> getLists() {
return lists;
}
public void setLists(List<Object> lists) {
this.lists = lists;
}
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", stage=" + stage +
", birth=" + birth +
", maps=" + maps +
", lists=" + lists +
", child=" + child +
'}';
}
}
Child:
package com.atguigu.springboot.pojo;
/**
* @Classname Child
trimmean的音标*/
public class Child {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}properties是什么文件
@Override
public String toString() {
return "Child{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
导⼊配置⽂件处理器,以后编写配置就有提⽰
zeromemory函数是什么功能<!--⽣成⾃⼰的配置元数据⽂件
包含⼀个Java注释处理器,在编译项⽬时调⽤该处理器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>  <optional>true</optional>
</dependency>
name: typ
age: 20
stage: true
birth: 2019/07/15
maps: {name: jack, age: 12}
lists:
- dog
- cat
child:
name: lucy
age: 11
测试:
package com.atguigu.springboot;
import com.atguigu.springboot.pojo.Person;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.st.context.SpringBootTest;
import st.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBoot01HelloworldApplicationTests {
@Autowired
private Person person;
@Test
public void contextLoads() {
System.out.String());
}
}
结果:
Person{name='typ', age=20, stage=true, birth=Mon Jul 15 00:00:00 CST 2019, maps={name=jack, age=12}, lists= [dog, cat], child=Child{name='lucy', age=11}}
application.properties
person.name=詹⾦斯
person.age=20
person.birth=2019/01/01
person.stage=true
person.maps.name=jack
person.maps.age=16
person.lists=a,b,c,d,e,f
person.child.name=露西
person.child.age=11
结果(有乱码):程序员工资一般多少2016
Person{name='ղ��˹', age=20, stage=true, birth=Tue Jan 01 00:00:00 CST 2019, maps={age=16, name=jack}, lists=[a, b, c, d, e, f], child=Child{name='¶��', age=11}}
File-->Settings
重新输⼊中⽂:
测试结果:
Person{name='詹⾦斯', age=20, stage=true, birth=Tue Jan 01 00:00:00 CST 2019, maps={age=16, name=jack}, lists= [a, b, c, d, e, f], child=Child{name='露西', age=11}}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。