通过properties配置文件给类属性赋值呢?
举例:
1、首先我在src/main/resources文件夹下新建个company.properties文件,设置一些数据
ge.companyName=\u6210\u90FD\u683C\u667A\u7F51\u7EDC\u79D1\u6280\u6709\u9650\u516C\u53F8
ge.telphone=028-88594556
ge.lawPerson=\u4F55\u61A8\u950B
2、新建一个类,叫做CompanyBean
@ConfigurationProperties(prefix="ge") 注解给属性添加前缀,因为在properties文件中属性前面有前缀ge,后面的属性名要和类中的属性名一致对应
@PropertySource(value= {"classpath:company.properties"}) 引入配置文件
package com.ge.springboot.bean;
import java.io.Serializable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@Configur