Skip to main content

Sort Examples

Sort ASC

DataManipulationModel dataManipulationModel = new DataManipulationModel();
dataManipulationModel.setSortModel(asc("gpa"));
GeneralSpecification<Student> studentGeneralSpecification = new GeneralSpecification<>(dataManipulationModel);
studentRepository.findAll(studentGeneralSpecification);

Sort DESC

DataManipulationModel dataManipulationModel = new DataManipulationModel();
dataManipulationModel.setSortModel(desc("gpa"));
GeneralSpecification<Student> studentGeneralSpecification = new GeneralSpecification<>(dataManipulationModel);
studentRepository.findAll(studentGeneralSpecification);

Multi Sort DESC and ASC (1)

DataManipulationModel dataManipulationModel = new DataManipulationModel();
dataManipulationModel.setSortModel(desc("gpa"), asc("firstName"));
GeneralSpecification<Student> studentGeneralSpecification = new GeneralSpecification<>(dataManipulationModel);
studentRepository.findAll(studentGeneralSpecification);

Multi Sort DESC and ASC (2)

DataManipulationModel dataManipulationModel = new DataManipulationModel();
dataManipulationModel.setSortModel(asc("gpa"), desc("firstName"));
GeneralSpecification<Student> studentGeneralSpecification = new GeneralSpecification<>(dataManipulationModel);
studentRepository.findAll(studentGeneralSpecification);