```
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@
Target(ElementType.FIELD)
@
Retention(RetentionPolicy.RUNTIME)
public @
interface PropertyMapping {
String value();
}
```
```
import java.lang.reflect.Field;
public class BeanMapper {
public static void copyProperties(Object source, Object destination) {
Class<?> sourceClass = source.getClass();
Class<?> destClass = destination.getClass();
Field[] sourceFields = sourceClass.getDeclaredFields();
for (Field sourceField : sourceFields) {
if (sourceField.isAnnotationPresent(PropertyMapping.class)) {
String sourceFieldName = sourceField.getName();
String destinationFieldName = sourceField.getAnnotation(PropertyMapping.class).value();
try {
Field destField = destClass.getDeclaredField(destinationFieldName);
sourceField.setAccessible(true);
destField.setAccessible(true);
Object value = sourceField.get(source);
destField.set(destination, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace(); // 处理异常,可以根据实际情况进行调整
}
}
}
}
}
```