我知道我可以创建一个这样的映射器:
@Mapper(componentModel="spring")
public interface MyMapper{
Run Code Online (Sandbox Code Playgroud)
这将导致:
@Component
public class MyMapperImpl{
Run Code Online (Sandbox Code Playgroud)
如何设置获取的bean名称:
@Component("name")
public class MyMapperImpl{
Run Code Online (Sandbox Code Playgroud)
目前不支持此功能。这是为此功能请求的问题mapstruct/mapstruct#1427 。
根据您的名称的外观,您可以使用自定义AnnotationBeanNameGenerator来生成组件扫描的映射器。
从 MapStruct 1.6(1.6.0.Beta1 已经发布)开始,可以使用新的@AnnotateWith
例如
@AnnotateWith(value = Service.class, elements = @Element(strings = "myMapperV2")
@Mapper(componentModel="spring")
public interface MyMapper {
// ...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3077 次 |
| 最近记录: |