Тёмный

Java Records: How to use a Java Record in a Spring Boot Application 

Dan Vega
Подписаться 63 тыс.
Просмотров 15 тыс.
50% 1

In this tutorial, you will learn about Java Records and how to use them in a Spring Boot Application. Records give you a way to create immutable data classes, cut down on verbosity, and improve readability. There are 3 really good use cases for using the Java Record type in Spring Boot and you will learn about 2 of them today.
👋🏻 Connect with me:
Website: www.danvega.dev
Twitter: / therealdanvega
Github: github.com/dan...
LinkedIn: / danvega
Newsletter: www.danvega.de...
SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️

Опубликовано:

 

21 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 31   
@uncopino
@uncopino 2 года назад
yes please, i’d love a tutorial about records with springdata
@khajalieubarrie5088
@khajalieubarrie5088 Год назад
Records can be used for defining DTO's but understanding how DTO's are manged in the persistence context will help in understanding how records can be used with springdata. This video is a thorough explanation on that: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-SyP258VgzSs.html
@kingstonmocktail7744
@kingstonmocktail7744 2 года назад
Would be great to see how we can use records in Spring Data
@DanVega
@DanVega 2 года назад
I will work on a tutorial for that. If you don't want to wait check out Spring Data JDBC, you won't be able to use them with JPA.
@uncopino
@uncopino 2 года назад
@@DanVega i looked into spring data jdbc, found a tutorial and the guy said “it’s preferred to work with immutable classes”. is that the reason why it works with records?
@nomad5297
@nomad5297 Год назад
Spring Dat JPA requires no args constructor and setters. record does not provide it
@letme4u
@letme4u 2 года назад
nice presentation with clear understanding. Please provide next with Spring data
@DanVega
@DanVega 2 года назад
Will do, thanks for watching!
@Pwjdjskw
@Pwjdjskw 11 месяцев назад
I was using Kotlin mainly because I love how simple it is to make data classes but now I am just finding out a very similar thing is in Java now?? Let’s go!
@Matlaps123
@Matlaps123 Год назад
Fantastic. Please do the JPA!
@DanVega
@DanVega Год назад
You can’t use records with JPA
@geoffreymakawa3554
@geoffreymakawa3554 Год назад
Hey Dan, what plugin are you using to be able to get those intellisense auto completion suggestions ?
@felixnjunge78
@felixnjunge78 Год назад
I think that is Github copilot
@aminesafi7261
@aminesafi7261 2 года назад
Great content, nice explanation, keep going 💪🏻
@kumarabhishek7877
@kumarabhishek7877 2 года назад
++ Spring Boot Latest update, Dan you are awesome keep sharing the best of you.
@MartenJurgenson
@MartenJurgenson Год назад
Hi! What is the Intellij plugin that helps you to complete code? It is suggesting in grey.
@DanVega
@DanVega Год назад
GitHub Copilot
@Adam-lx4et
@Adam-lx4et 7 месяцев назад
Looks good in theory but when record has a lot of properties then I can imagine its not great to read and write when using the constructor, in those cases a standard class with a lombok builder would be a more readable approach.
@VarshaGit
@VarshaGit 2 месяца назад
can we use records for request and response body in spring-rest?
@domincwild
@domincwild 2 года назад
What about classes which have a lot of properties? This is nice for small data classes, but what if it has something like 20 different properties that must be set?
@DanVega
@DanVega 2 года назад
It will work for those as well. I have IntelliJ automatically put each argument on a new line for readability.
@domincwild
@domincwild 2 года назад
@@DanVega That's good. Although I'm mainly thinking about usage. So it would be readable inside the class, but when its used somewhere in the code, a 20 arg constructor is pretty unweildy. Say I wanted most of these values to have sensible defaults, but still be immutable and gain the advantage of a record type. Something usually solved with the builder pattern, but wondering if this could be applied in some way to simplify that.
@DanVega
@DanVega 2 года назад
There isn't much you can do in that case. You can't use the compact constructor to delegate to another constructor so setting defaults that way isn't possible. If you need something like that just use a regular class and use records where possible.
@jythejavaguy
@jythejavaguy 2 года назад
@@domincwild One approach is to write custom constructors that delegate to the canonical constructor with default values. And if you need something more like a builder, there are third party libraries that provide builder functionality for Java Records, but you can write your own "wither" if you want: For example: record Point3D(int x, int y, int z) { Point3D() { this(0,0,0); } public Point3D withX(int newX) { return new Point3D(newX, y, z); } } var point = new Point3D(); point = point.withX(5);
@franciscorevelles
@franciscorevelles Месяц назад
so how do java records and spring data fit together?
@graflaszlo
@graflaszlo Год назад
Just keep it in this way :-)
@glowiever
@glowiever 2 года назад
I still feel scared that somehow there's a jpa bug waiting around somewhere when I use record...
@jopadjr
@jopadjr 2 года назад
9th.. Thanks.
@jassebozic2504
@jassebozic2504 11 месяцев назад
👍
@travellogger5080
@travellogger5080 Год назад
Hm... Hm... Case class?
@felixnjunge78
@felixnjunge78 Год назад
Hello Dan, while using records can I annotate, Json annotations, @Column annotations as I would one a normal class
Далее
Кольцо Всевластия от Samsung
01:00
Просмотров 528 тыс.
Deep Dive with Java Records with Jason Young
29:39
Просмотров 10 тыс.
Spring Boot @Value annotation
14:30
Просмотров 4,4 тыс.
Let’s Set the Records Straight
53:06
Просмотров 7 тыс.
Test Driven Development (TDD) in Spring
51:09
Просмотров 27 тыс.