如何将配置文件转换成List<Map<String,Object>>格式,在此声明一下,这个方法不是原创,而是解和文章和自己的内容进行总接记录
首先是配置文件,先独立创建一个配置文件
ids:
platIds:
- promoteClass: sg-col-4-of-12 s-result-item s-asin sg-col-4-of-16 AdHolder sg-col s-widget-spacing-small sg-col-4-of-20
productNameClass: a-text-normal
productUrlClass: a-link-normal
productStarArowAttributeClass: aria-label
productReviewNumClass: a-size-base
- promoteClass: s-result-item s-asin sg-col-0-of-12 sg-col-16-of-20 AdHolder sg-col s-widget-spacing-small sg-col-12-of-16
productNameClass: a-text-normal
productPhotoClass: s-image
productStarArowClass: a-size-small
productStarArowAttributeClass: aria-label
productReviewNumClass: a-size-base
文件存放的位置,文件名application-cfgPrefixPlatIds.yml
代码中需要进行引入的内容
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "ids")
public class CfgPrefixPlatIds {
private List<Map<String,String>> platIds;
public List<Map<String, String>> getPlatIds() {
return platIds;
}
public void setPlatIds(List<Map<String, String>> platIds) {
this.platIds = platIds;
}
}
在业务代码中需要识别的代码
@Autowired
private CfgPrefixPlatIds cfgPrefixPlatIds;
List<Map<String, String>> platIds = cfgPrefixPlatIds.getPlatIds();