写个配置文件存放手机号码,在接收手机号码地方判断配置与文件中相同的手机号码就过滤此手机号码

写个配置文件存放手机号码,在接收手机号码地方判断配置与文件中相同的手机号码就过滤此手机号码

方案一:将所有电话号码存到库中,然后从数据库读取,和传过来的手机号做匹配,库中若存在,则过滤掉这个手机号码,不存在,写入过滤后的集合汇总,代码如下:
List<String> phoneList = getAllPhoneNum(); //所有号码的集合
List<String> filterPhoneList = new ArrayList<>(); //过滤后的电话号码集合
if(!phoneList.contains(phoneNum)){
filterPhoneList.add(phoneNum)
}
方案二,将所有电话号码放到配置文件yml中,读取即可,代码如下
phoneNum:
list:
- xxxxxxxxxxx
- xxxxxxxxxxx
- xxxxxxxxxxx
- xxxxxxxxxxx
- xxxxxxxxxxx
package com.xxx.xxx.config;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "phoneNum")
public class PhoneNumConfig {
private List<String> list;
public void setList(List<String> list) {
this.list = list;
}
public List<String> getList() {
return list;
}
}