在我的 dto 类中:
private String password;
在我的模型类中:
private byte[] password;
我想使用 mapStruct 将 String 转换为 byte[]。有人可以帮忙吗
提前致谢。
最佳答案
最好是提供一个默认的方法来映射 String
和 byte[]
.
例如:
@Mapper
public MyMapper {
Model fromDto(Dto dto);
default byte[] toBytes(String string) {
return string != null ? string.getBytes() : null;
}
}
有了这个,您将让 MapStruct 自动处理
Dto
之间的所有其他字段。和 Model
并留下 String
之间的映射和 byte[]
到 toBytes
方法。
关于spring-boot - map 结构 : How to convert String to byte[] using mapstruct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60420184/