Science & Technology

#24 Spring Boot Project | Response Entity and GetByID

by Telusko

Share:

✨ Temas principales

  • Obtener un producto por IDSe añade una ruta en el controlador que recibe el ID como variable de ruta y solicita al servicio el producto correspondiente. El repositorio usa findById para buscarlo. 2:37
  • Formato de la fechaSe aplica @JsonFormat al campo de fecha de lanzamiento para controlar cómo aparece la fecha en la respuesta JSON. 6:14
  • ResponseEntity y códigos de estadoSe usa ResponseEntity para devolver tanto los datos como un código HTTP, y se comprueba si el producto existe antes de responder. 8:19

🧠 Conclusiones clave

  • Manejo de resultados opcionalesfindById devuelve un Optional, porque puede que no haya un producto con ese ID; el controlador puede comprobar el resultado y responder en consecuencia. 4:11
  • Respuestas de éxito y errorPara una solicitud válida se devuelve el producto con el estado OK; si no existe, se responde con Not Found. 11:27

📚 Lecciones aprendidas

  • Elegir un formato de fecha legibleEl patrón de formato debe usar las letras correctas; en el ejemplo, se cambia a una M mayúscula para mostrar bien el mes. 7:48
  • No usar valores predeterminados como solución definitivaDevolver un producto vacío o null puede simplificar el ejemplo, pero el manejo de productos inexistentes debe elegirse según el caso. 12:28

🏁 Conclusión y próximos pasos

  • Próxima funciónLa búsqueda de un producto por ID queda lista para el ejemplo; en el siguiente video se verá cómo añadir un producto. 13:00

Transcript excerpt

0:00 so now it's time to go one step forward so basically in the last video we have seen how do you get all the products on the screen right but now what if you want to know about each product what I'm talking about is let's go back to the front end so I have changed the front end for this video so you will see that in the description and let me open that new code in vs code yeah okay so this is the front end two as you can go with the names so the first one was one this is two so this is a UI nothing much changes

0:31 only one particular change so if I click on SRC you can see there's a folder called components inside this component there's folder called a product so basically uh let's go back to first of all the home we don't have navigations here right navigations is is here so I can basically get into get on the products and I can call this product which is here now what is happening in the products is so basically your client will send a request to the server for one product not all of course you will get all first

🔒 The full, searchable transcript is available with Pro.

🔒 Unlock Premium Features

This is a premium feature. Upgrade to unlock unlimited Q&A, transcripts, mindmaps, and translations.

🔒 Unlock Premium Features

Access to Chat is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Mindmap is a premium feature. Upgrade now to unlock unlimited studying tools.

🔒 Unlock Premium Features

Access to Translation is a premium feature. Upgrade now to unlock unlimited studying tools.

Get unlimited summaries, Q&A, transcripts and more with Pro

Upgrade to Pro

Suggestions

🔒 Unlock Premium Features

Access to AI Suggestions is a premium feature. Upgrade now to unlock unlimited studying tools.