Class BeanPath

java.lang.Object
org.miaixz.bus.core.beans.path.BeanPath
All Implemented Interfaces:
Iterator<BeanPath>

public class BeanPath extends Object implements Iterator<BeanPath>
Bean路径表达式,用于获取多层嵌套Bean中的字段值或Bean对象 根据给定的表达式,查找Bean中对应的属性值对象。 表达式分为两种:
  1. .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值
  2. []表达式,可以获取集合等对象中对应index的值
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • BeanPath

      public BeanPath(String expression)
      构造
      Parameters:
      expression - 表达式
  • Method Details

    • of

      public static BeanPath of(String expression)
      创建Bean路径
      Parameters:
      expression - 表达式
      Returns:
      BeanPath
    • getNode

      public Node getNode()
      获取节点
      Returns:
      节点
    • getChild

      public String getChild()
      获取子表达式
      Returns:
      子表达式
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<BeanPath>
    • next

      public BeanPath next()
      Specified by:
      next in interface Iterator<BeanPath>
    • getValue

      public Object getValue(Object bean)
      获取路径对应的值
      Parameters:
      bean - Bean对象
      Returns:
      路径对应的值
    • setValue

      public Object setValue(Object bean, Object value)
      设置路径对应的值,如果路径节点为空,自动创建之
      Parameters:
      bean - Bean对象
      value - 设置的值
      Returns:
      beans。如果在原Bean对象基础上设置值,返回原Bean,否则返回新的Bean
    • toString

      public String toString()
      Overrides:
      toString in class Object