简体   繁体   English

BeanMapping:在映射表达式中替换集合中的值?

[英]BeanMapping: Replace value in set within mapping expression?

I have a string Set I'm mapping into a bean for a PDF form content extraction:我有一个字符串 Set 我正在映射到一个用于 PDF 表单内容提取的 bean:

@Mapping(target = "targetFieldName", expression = "java(contentMapperService.convertStringToSet(pdfFieldsMap.get(\"PDF_field_name\")))")

Let's say the input String from the PDF field is "apple,banana"假设来自 PDF 字段的输入字符串是“apple,banana”

If we find the value "apple", we want to replace it with "apples" before the set is mapped to the target.如果我们找到值“apple”,我们希望在集合映射到目标之前将其替换为“apples”。

Is this possible to do within an expression?这可以在表达式中完成吗?

You can create a method with your specific logic and use it inside the expression您可以使用您的特定逻辑创建一个方法并在表达式中使用它

Cause you don't provide the mapper, take this as an example.因为你没有提供映射器,以这个为例。

@Mapper(componentModel = "spring")
public abstract class MyMapper {

    @Mapping(target = "targetFieldName", expression = "java(setTargetFieldName(source.getPdfFieldName()))")
    public abstract Target toTarget(Source source);

    protected String setTargetFieldName(String pdf_field_name){
        return pdf_field_name.replace("apple", "apples");
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM