All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.wenhao.jpa.specification.AbstractSpecification Maven / Gradle / Ivy

The newest version!
package com.github.wenhao.jpa.specification;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.util.StringUtils;

import java.io.Serializable;

import javax.persistence.criteria.From;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;

abstract class AbstractSpecification implements Specification, Serializable {
    public String getProperty(String property) {
        if (property.contains(".")) {
            return StringUtils.split(property, ".")[1];
        }
        return property;
    }

    public From getRoot(String property, Root root) {
        if (property.contains(".")) {
            String joinProperty = StringUtils.split(property, ".")[0];
            return root.join(joinProperty, JoinType.LEFT);
        }
        return root;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy