# 自定义属性 boot.userName = yuxi
@Value(value = "${boot.userName}")
private String userName;
# 复杂属性 test.id=1 test.name=xiaoyuxixi test.money=100000000
//需要注意这个属性是必须的
@ConfigurationProperties(prefix = "test")
public class Account {
private int id;
private String name;
private double money;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
@Override
public String toString() {
return "Account{" +
"id=" + id +
", name='" + name + '\'' +
", money=" + money +
'}';
}
}
@RestController
// 这个属性也是必须的
@EnableConfigurationProperties({Account.class})
public class HelloController {
//自定义属性
@Value(value = "${boot.userName}")
private String userName;
@Autowired
private Account account;
/**
* 复杂 属性自定义
*
* @return
*/
@RequestMapping("/hard")
public Object getHardProperties() {
return account;
}
/**
* welcome spring boot
*
* @return
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "Greetings from Spring Boot! ";
}
/**
* 简单 属性自定义
*
* @return
*/
@RequestMapping("/user")
public String getProperties() {
System.out.println(userName);
return userName;
}
}
# 配置文件获取 lakala.id=1 lakala.name=xiaoyuxixi lakala.money=100000000
@Configuration @PropertySource(value = "classpath:test.properties")
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有