首页
登录 | 注册

拦截非字符串型参数取值

拦截非字符串型参数取值

【1】 准备枚举类:

@Getter
@AllArgsConstructor
public enum QualificationType {

    LEGAL_IDENTITY_CARD_FRONT("LEGAL_IDENTITY_CARD_FRONT", 2, "法人身份证(正)"),

    LEGAL_IDENTITY_CARD_BACK("LEGAL_IDENTITY_CARD_BACK", 3, "法人身份证(反)"),

    BUSINESS_LICENSE("BUSINESS_LICENSE", 1, "营业执照证"),

    AGENT_IDENTIFY_CARD_FRONT("AGENT_IDENTIFY_CARD_FRONT", 4, "代理人身份证(正)"),

    AGENT_IDENTIFY_CARD_BACK("AGENT_IDENTIFY_CARD_BACK", 5, "代理人身份证(反)"),

    AGENT_ATTORNEY("AGENT_ATTORNEY", 6 ,"代理委托书"),
    ;


    /**
     * 资质信息枚举Map
     */
    public static Map<String, String> qualificationMap;

    static {
        qualificationMap = new LinkedHashMap<>();
        qualificationMap.put(QualificationType.LEGAL_IDENTITY_CARD_FRONT.code, QualificationType.LEGAL_IDENTITY_CARD_FRONT.desc);
        qualificationMap.put(QualificationType.LEGAL_IDENTITY_CARD_BACK.code, QualificationType.LEGAL_IDENTITY_CARD_BACK.desc);
        qualificationMap.put(QualificationType.BUSINESS_LICENSE.code, QualificationType.BUSINESS_LICENSE.desc);
        qualificationMap.put(QualificationType.AGENT_IDENTIFY_CARD_FRONT.code, QualificationType.AGENT_IDENTIFY_CARD_FRONT.desc);
        qualificationMap.put(QualificationType.AGENT_IDENTIFY_CARD_BACK.code, QualificationType.AGENT_IDENTIFY_CARD_BACK.desc);
        qualificationMap.put(QualificationType.AGENT_ATTORNEY.code, QualificationType.AGENT_ATTORNEY.desc);
    }

    private String code;

    private Integer num;

    private String desc;

    /**
     * 根据宝付订单状态映射
     */
    public static QualificationType mappingByNum(Integer num) {
        for(QualificationType qualificationType : QualificationType.values()){
            if(qualificationType.getNum().equals(num)){
                return qualificationType;
            }
        }
        return null;
    }

}

【2】构建资质枚举信息Map

    /**
     * 资质信息枚举Map
     */
    public static Map<String, String> qualificationMap;

    static {
        qualificationMap = new LinkedHashMap<>();
        qualificationMap.put(QualificationType.LEGAL_IDENTITY_CARD_FRONT.code, QualificationType.LEGAL_IDENTITY_CARD_FRONT.desc);
        qualificationMap.put(QualificationType.LEGAL_IDENTITY_CARD_BACK.code, QualificationType.LEGAL_IDENTITY_CARD_BACK.desc);
        qualificationMap.put(QualificationType.BUSINESS_LICENSE.code, QualificationType.BUSINESS_LICENSE.desc);
        qualificationMap.put(QualificationType.AGENT_IDENTIFY_CARD_FRONT.code, QualificationType.AGENT_IDENTIFY_CARD_FRONT.desc);
        qualificationMap.put(QualificationType.AGENT_IDENTIFY_CARD_BACK.code, QualificationType.AGENT_IDENTIFY_CARD_BACK.desc);
        qualificationMap.put(QualificationType.AGENT_ATTORNEY.code, QualificationType.AGENT_ATTORNEY.desc);
    }

【3】枚举类通过map转为list

 /**
     * 枚举类通过map转为list
     * @param map         map集合
     * @return           资质信息集合
     */
    private List<DirQualification> transferEnumMapToList(Map<String,String> map){
        List<DirQualification> dirQualificationList = new ArrayList<>();

        Iterator<Map.Entry<String, String>> entries = map.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<String, String> entry = entries.next();
            DirQualification dirQualification = new DirQualification();
            dirQualification.setCode(entry.getKey());
            dirQualification.setDesc(entry.getValue());
            dirQualificationList.add(dirQualification);
        }
      return  dirQualificationList;
    }

【4】判断枚举Map中是否含有请求参数值

 boolean contains = map.containsKey(key); 
该方法判断Map集合对象中是否包含指定的键名。如果Map集合中包含指定的键名,则返回true,否则返回false。

 

 

 

 

 

 

 



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.008 s.
京ICP备10005923号