انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-029-L05

الإسقاطات (Projections) والترقيم

  • الدرس 5 من 7
  • Junior
في هذا الدرس 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.
  • Pageable carries page number, size, and sort; PageRequest.of(0, 20, Sort.by("name")).
  • Return Page<T> (with total count) or Slice<T> (no count query).
  • Map to a response DTO in the service; never return entities from controllers.
تفاصيل المخطط المبدئي

عرض عملي

java
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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.