1、配置文件 resources/config/application.properties
// 随机id, ID:拼接随机的uuid字符串
product.id=ID:${random.uuid}
product.name=da mao mao
// 随机的int类型数据
product.weight=${random.int}
// 500到600之间的随机数,左右不包含
product.firstLinePrice=${random.int(500,600)}
// 300到400之间的随机数,左右都包含
product.endLinePrice=${random.int[300,400]}
// 获取上面的product.name的值
product.remark=${product.name}
2、测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class Springboot01ApplicationTests {
@Value("${product.id}")
private String id;
@Value("${product.name}")
private String name;
@Value("${product.weight}")
private Integer weight;
@Value("${product.firstLinePrice}")
private Integer firstLinePrice;
@Value("${product.endLinePrice}")
private Integer endLinePrice;
@Value("${product.remark}")
private String remark;
@Test
public void testProperties() {
System.out.println(id + "
" + name + "
" + weight + "
" +
firstLinePrice + "
" + endLinePrice + "
" + remark);
}
}
3、测试结果
ID:f0158ded-844f-456e-879b-efa36f4c593f
da mao mao
1877884196
506
315
da mao mao