У меня есть эти два объекта
Код: Выделить всё
@Entity
@Table(name = "course")
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "course")
private List reviews = new ArrayList();
....contructors, getters and setters
}
@Entity
@Table(name = "review")
public class Review {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String rating;
@ManyToOne
private Course course;
....contructors, getters and setters
}
Код: Выделить всё
@Repository
public interface CourseRepository extends JpaRepository {
}
Код: Выделить всё
@Service
public class CourseService {
@Autowired
CourseRepository courseRepository;
public Page getCourses(Pageable pageable) {
return courseRepository.findAll(pageable);
}
}
Код: Выделить всё
@RestController
@RequestMapping("/api")
public class CourseController {
@Autowired
CourseService courseService;
@RequestMapping(value="/courses", method= RequestMethod.GET)
public ResponseEntity
> readInteractionsPagedParam(Pageable pageable) {
Page pageCourse = courseService.getCourses(pageable);
... To DTO and return it
}
}
Мне нужно что-то вроде этого, но я попробовал их и сортировал только сущность. Конечно, обзор сущности никогда не сортируется
Код: Выделить всё
.../api/courses?page=0&size=10&sort=name,asc&sort=reviews.rating,asc
.../api/courses?page=0&size=10&sort=name,asc&sort=reviews.rating,desc
.../api/courses?page=0&size=10&sort=name,desc&sort=reviews.rating,asc
.../api/courses?page=0&size=10&sort=name,desc&sort=reviews.rating,desc
Подробнее здесь: https://stackoverflow.com/questions/711 ... h-pageable