public interface EntityConverter<F, T> {
T convert(F from, T to);
}
@Service
public class MemberConverter implements EntityConverter<MemberDto, Member> {
@Override
public Member convert(MemberDto from, Member to) {
Objects.requireNonNull(from);
Objects.requireNonNull(to);
to.MemberId(from.getMemberId());
to.setLastJoinDt(from.getLastJoinDt());
.
.
.
return to;
}
}
@Slf4j
@Service
public class EntityConverterFactory<C extends EntityConverter<F, T>, F, T> {
@Autowired
Map<String, EntityConverter<F, T>> converters;
public EntityConverter<F, T> build(Class<C> clazz) {
String name = clazz.getSimpleName().substring(0, 1).toLowerCase() + clazz.getSimpleName().substring(1);;
return converters.get(name);;
}
}
在这种情况下,
下面的代码警报未选中的分配。
如何避免此警告?
@Autowired
private EntityConverterFactory entityConverterFactory;
.
.
EntityConverter<MemberDto, Member> converter = entityConverterFactory.build(MemberConverter.class);