spring - Mapstruct:从注入的映射器调用函数
问题描述
我有一个像这样的映射器:
@Mapper(uses = {DateMapper.class, AuthenticationMapper.class})
public interface LocalUserMapper {
LocalUserMapper INSTANCE = Mappers.getMapper(LocalUserMapper.class);
@Mapping(target = "domains", source = "localUser.directDomains")
@Mapping(target = "phone", source = "localUser.phoneNumber")
@Mapping(target = "displayName", source = "localUser.displayPartyName")
@Mapping(target = "authenticationMethod", expression =" java(mapAuthenticationMethodForLocalUser(localUser))")
UserDTO convertLocalUser(LocalUser localUser);
}
映射字段“authenticationMethod”我想在本地做一些事情,然后让 AuthenticationMapper(见上文)做剩下的(注意:我不能改变 AuthenticationMapper 的主要映射功能以满足我的需要,它用于其他地方)理想情况下,使用此函数进行映射(作为表达式)
default String mapAuthenticationMethodForLocalUser(LocalUser localUser) {
AuthenticationMethod authenticationMethod = localUser.getAuthenticationMethod();
if (localUser.useTwoLayerAuthentication()) {
// do some stuff and return something
} //else
return **authenticationMethodMapper**.convertAuthenticationMethod(authenticationMethod);
}
这不起作用,因为生成 impl 时 authenticationMethodMapper 不知何故是未知字段
有人知道这样做的好方法吗?谢谢!
解决方案
推荐阅读
- go - 什么时候使用嵌入?
- c++ - V8 - 向 Javascript 代码公开一个非 void C++ 函数
- jupyter-notebook - Jupyter Notebook:直接将 html 下载到我的下载文件夹(Windows)
- sql - 如何使用 filter 和 groupBy 在 Scala 和 Quill 中表达这个 SQL 查询?
- apple-sign-in - 使用 Apple 登录按钮未出现在网站上
- reactjs - 如何使无线电输入保存状态并再次使用它
- swift - 从选择器存储值并将其传递给函数
- reactjs - useEffect 修复中的无限循环?
- c++ - 对...collect2:error:ld 的未定义引用返回 1 个退出状态
- python-3.x - 在 Python 3 中将字典返回给函数