如何读取properties文件配置,完成对象属性赋值

该文章展示了一个Java类OrderDto,它使用SpringBoot的注解进行配置。类包含订单ID、价格、金额、用户列表和消息列表属性。订单消息列表中每个Msg对象都有名字和年龄。此外,文章还展示了对应的properties配置,如订单属性和用户列表。
摘要由CSDN通过智能技术生成
@Component
@ConfigurationProperties(prefix = "order")
@Data
public class OrderDto {

    private String orderId;
    private String orderPrice;

    @Value("${amount}")
    private BigDecimal orderAmount;

    @Value("#{'${order.user.list}'.split(',')}")
    private List<String> users;

    private List<Msg> msgs;

    @Data
    public static class Msg{
        private String name;
        private Integer age;
    }

}
  1. properties
order.orderId="00100"
order.orderPrice=20.78

order.msgs[0].name=zs
order.msgs[0].age=1
order.msgs[1].name=ls
order.msgs[1].age=2

amount=30

order.user.list=zs,ls,ww
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值