Spring使用@Value注解各种类型的值
2021-02-18 12:17
标签:obj lis value @Value abc object tst str ica 在application.properties写入下面代码 test.boolean=true 使用junit进行测试 @RunWith(SpringRunner.class) Spring使用@Value注解各种类型的值 标签:obj lis value @Value abc object tst str ica 原文地址:https://www.cnblogs.com/liangblog/p/12690815.html
test.string=abc
test.integer=123
test.long=123
test.float=1.2345678123456
test.double=1.2345678123456
test.array=1,3,4,5,6,1,2,3
test.list=1,3,4,5,6,1,2,3
test.set=1,3,4,5,6,1,2,3
test.map={name:"张三", age:18}
@SpringBootTest(classes = {ApplicationBootstrap.class})
public class DemoTest {
@Value("${test.boolean}")
private Boolean testBoolean;
@Value("${test.string}")
private String testString;
@Value("${test.integer}")
private Integer testInteger;
@Value("${test.long}")
private Long testLong;
@Value("${test.float}")
private Float testFloat;
@Value("${test.double}")
private Double testDouble;
@Value("#{‘${test.array}‘.split(‘,‘)}")
private String[] testArray;
@Value("#{‘${test.list}‘.split(‘,‘)}")
private List
@Value("#{‘${test.set}‘.split(‘,‘)}")
private Set
@Value("#{${test.map}}")
private Map
}
文章标题:Spring使用@Value注解各种类型的值
文章链接:http://soscw.com/index.php/essay/57034.html