Class ProjectionUtils

java.lang.Object
cn.dinodev.spring.commons.utils.ProjectionUtils

public class ProjectionUtils extends Object
Author:
Cody Lu
  • Constructor Details

    • ProjectionUtils

      public ProjectionUtils()
  • Method Details

    • projectProperties

      public static void projectProperties(Object source, Object target) throws org.springframework.beans.BeansException
      Copy the property values of the given source bean into the target bean.

      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.

      Parameters:
      source - the source bean
      target - the target bean
      Throws:
      org.springframework.beans.BeansException - if the projecting failed
      See Also:
      • BeanWrapper
    • projectProperties

      public static void projectProperties(Object source, Object target, Class<?> editable) throws org.springframework.beans.BeansException
      Copy the property values of the given source bean into the given target bean, only setting properties defined in the given "editable" class (or interface).

      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.

      Parameters:
      source - the source bean
      target - the target bean
      editable - the class (or interface) to restrict property setting to
      Throws:
      org.springframework.beans.BeansException - if the projecting failed
      See Also:
      • BeanWrapper
    • projectProperties

      public static void projectProperties(Object source, Object target, String... ignoreProperties) throws org.springframework.beans.BeansException
      project the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties".

      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.

      This is just a convenience method. For more complex transfer needs, consider using a full BeanWrapper.

      Parameters:
      source - the source bean
      target - the target bean
      ignoreProperties - array of property names to ignore
      Throws:
      org.springframework.beans.BeansException - if the projecting failed
      See Also:
      • BeanWrapper
    • projectPropertiesWithView

      public static void projectPropertiesWithView(Object source, Object target, @Nonnull Class<?> activeView) throws org.springframework.beans.BeansException
      project the property values of the given source bean into the target bean.

      Note: The property of source or target which not in json view (activeView) will silently be ignored.

      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.

      Parameters:
      source - the source bean
      target - the target bean
      activeView - the active json view
      Throws:
      org.springframework.beans.BeansException - if the projecting failed
      See Also:
      • BeanWrapper
    • projectPropertiesWithView

      public static void projectPropertiesWithView(Object source, Object target, @Nullable Class<?> editable, @Nonnull Class<?> activeView) throws org.springframework.beans.BeansException
      project the property values of the given source bean into the given target bean, only setting properties defined in the given "editable" class (or interface).

      Note: The property of source or editable which not in json view (activeView) will silently be ignored.

      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.

      Parameters:
      source - the source bean
      target - the target bean
      editable - the class (or interface) to restrict property setting to
      activeView - the active json view
      Throws:
      org.springframework.beans.BeansException - if the projecting failed
      See Also:
      • BeanWrapper