-1

我有一个实体类 PersonEntity 并且对应于我有 Dto 类

@Entity(value="person")

class PersonEntity{

String name;

String id;

}

**DTO** 

class PersonDto{
String name;

String id;

String desc; (This is a lookup from a map with id attribute)
}

In my mapper class, I am able to change my entity list to Dto list with below code.

public interface MyMapper{

List<PersonDto> entityListToDtoList(<List<PersonEntity>)

}

如何使用我的查找图来获取描述并在我的 DTO 类中设置。我无法弄清楚如何使用以下代码确定值。

List<PersonDto> entityListToDtoList(<List<PersonEntity>,@Context Map<String,String> lookupMap)
4

1 回答 1

0

您必须定义PersonEntitytoPersonDto方法并为此添加一个@Mapping表达式。请参见以下示例:

    @Mapping( target = "desc", expression = "java(lookupMap.get(person.getId()))" )
    PersonDto entityToDto(PersonEntity person, @Context Map<String, String> lookupMap);

    List<PersonDto> entityListToDtoList(List<PersonEntity> persons, @Context Map<String, String> lookupMap);
于 2022-01-17T16:30:50.917 回答