0

I have an entity with the following properties

public class DistributorMasterData  implements Serializable {
    @Id
    @Column(updatable = false, nullable = false)
    private Long id;
    private String distributorName;
    private String distributorCode;
    private String ownerName;
    private String address;

}

I can write specification to filter data. But the filtering conditions are defined by me in the above way

 @Override
    public Predicate toPredicate(Root<DistributorMasterData> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
        return codeSpec()
                .and(idSpec())
                .toPredicate(root, query, criteriaBuilder);
    }


    private Specification<DistributorMasterData> idSpec() {
        return ((root, query, criteriaBuilder) -> Objects.isNull(criteria.getDistributorIds()) ?
                null : root.get(DistributorMasterData_.ID).in(criteria.getDistributorIds())
        );
    }

    private Specification<DistributorMasterData> codeSpec() {
          return Objects.nonNull(criteria.getDistributorCode()) ? buildStringSpecification(criteria.getDistributorCode(), DistributorMasterData_.distributorCode) : null;
    }

But what I want to achieve is total dynamic control where user will decide if the want to find data which are greater than the value the have selected or less than or equal. How can I achieve that?

0 Answers0