الإسقاطات (Projections) والترقيم
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
return only the columns a screen needs, one page at a time.
الموضوعات المخطط لها
- A projection is a read-only view: an interface with getters or a record.
- It selects only the needed columns, no entity tracking.
Pageablecarries page number, size, and sort;PageRequest.of(0, 20, Sort.by("name")).- Return
Page<T>(with total count) orSlice<T>(no count query). - Map to a response DTO in the service; never return entities from controllers.
تفاصيل المخطط المبدئي
عرض عملي
public record ProductListItem(Long id, String name, BigDecimal priceAmount) {}
@Query("select new com.shop.ProductListItem(p.id, p.name, p.price.amount) from Product p")
Page<ProductListItem> list(Pageable pageable);اختبر فهمك
What does Page have that Slice does not?
أظهر الإجابة
The total count.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.