将一个类中的值通过setter和getter传递给另一个类型

public static <T> T entityToDto(Object entity, Class<T> dtoType) {
	T instance;
	try {
		instance = dtoType.getDeclaredConstructor().newInstance();
	} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
		throw new RuntimeException(e);
	}
	// 反射entity 获取getter
	Class<?> entryType = entity.getClass();
	Arrays.stream(dtoType.getMethods()).filter(
		method -> method.getName().startsWith("set")
	).forEach(method -> {
		String methodName = method.getName().replace("set", "get");
		try {
			Object value = entryType.getMethod(methodName).invoke(entity);
			method.invoke(instance, value);
		} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {}
	});
	return instance;
}