侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录

代码

Dettan
2021-04-10 / 0 评论 / 0 点赞 / 145 阅读 / 481 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
/**
* Copy the property values of the given source bean into the given target bean.
* <p>Note: The source and target classes do not have to match or even be derived
* from each other, as long as the properties match. Any bean properties that the
* source bean exposes but the target bean does not will silently be ignored.
* @param source the source bean
* @param target the target bean
* @param editable the class (or interface) to restrict property setting to
* @param ignoreProperties array of property names to ignore
* @throws BeansException if the copying failed
* @see BeanWrapper
*/
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
	@Nullable String... ignoreProperties) throws BeansException {

Assert.notNull(source, "Source must not be null");
Assert.notNull(target, "Target must not be null");

Class<?> actualEditable = target.getClass();
if (editable != null) {
	if (!editable.isInstance(target)) {
		throw new IllegalArgumentException("Target class [" + target.getClass().getName() +
				"] not assignable to Editable class [" + editable.getName() + "]");
	}
	actualEditable = editable;
}
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);

for (PropertyDescriptor targetPd : targetPds) {
	Method writeMethod = targetPd.getWriteMethod();
	if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) {
		PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
		if (sourcePd != null) {
			Method readMethod = sourcePd.getReadMethod();
			if (readMethod != null &&
					ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
				try {
					if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
						readMethod.setAccessible(true);
					}
					Object value = readMethod.invoke(source);
					if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {
						writeMethod.setAccessible(true);
					}
					writeMethod.invoke(target, value);
				}
				catch (Throwable ex) {
					throw new FatalBeanException(
							"Could not copy property '" + targetPd.getName() + "' from source to target", ex);
				}
			}
		}
	}
}
}

参数相关
package com.jsh.erp.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;

/**
 * @author jishenghua qq752718920  2018-10-7 15:26:27
 */
public class ParamUtils {
    public static String getPageOffset(Integer currentPage, Integer pageSize) {
        if (currentPage != null && pageSize != null) {
            int offset = (currentPage - 1) * pageSize;
            if (offset <= 0) {
                return "0";
            } else {
                return new StringBuffer().append(offset).toString();
            }
        }
        return null;
    }
    public static Integer getNumberPageOffset(Integer currentPage, Integer pageSize) {
        if (currentPage != null && pageSize != null) {
            int offset = (currentPage - 1) * pageSize;
            if (offset <= 0) {
                return 0;
            } else {
                return offset;
            }
        }
        return null;
    }
    public static Integer getNumberPageRows(Integer currentPage, Integer pageSize) {
        if (currentPage != null && pageSize != null) {
            int rows = (currentPage) * pageSize;
            if (rows <= 0) {
                return 0;
            } else {
                return rows;
            }
        }
        return null;
    }

    public static HashMap<String, String> requestToMap(HttpServletRequest request) {

        HashMap<String, String> parameterMap = new HashMap<String, String>();
        Enumeration<String> names = request.getParameterNames();
        if (names != null) {
            for (String name : Collections.list(names)) {
                parameterMap.put(name, request.getParameter(name));
                /*HttpMethod method = HttpMethod.valueOf(request.getMethod());
                if (method == GET || method == DELETE)
                    parameterMap.put(name, transcoding(request.getParameter(name)));
                else
                    parameterMap.put(name, request.getParameter(name));*/
            }
        }
        return parameterMap;
    }
}
0

评论区