الـ Controllers: حافة HTTP
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
write a thin controller.
الموضوعات المخطط لها
- A controller translates HTTP to a method call and the result back to HTTP.
- It handles paths, methods, status codes, and request/response bodies.
- It contains no business rules and no database code.
@RestControllerreturns data (JSON), not pages.
تفاصيل المخطط المبدئي
عرض عملي
@RestController
@RequestMapping("/products")
class ProductController {
private final ProductService service;
ProductController(ProductService service) { this.service = service; }
@GetMapping("/{id}")
ProductResponse get(@PathVariable long id) { return service.get(id); }
}اختبر فهمك
Where does "a discount cannot exceed 50%" go?
أظهر الإجابة
In the service, not the controller.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.