Hello,
I'm a bit lost with how to correctly display stuff on Thymeleaf.
Let's say I have a User entity :
@Entity
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(name = "uk_users_username", columnNames = "username"),
@UniqueConstraint(name = "uk_users_email", columnNames = "email") })
public class User extends BaseEntity {
@Column(name = "username", nullable = false, unique = true, length = 50)
@NotBlank
@Size(min = 3, max = 50)
private String username;
@Column(name = "email", nullable = false, unique = true, length = 254)
@NotBlank
@Size(max = 254)
private String email;
@Column(name = "password_hash", nullable = false, length = 100)
@NotBlank
@Size(min = 60, max = 100) // longueur hash bcrypt
private String passwordHash;
private boolean enabled = false;
private boolean emailVerified = false;
// getters and setters
}
and I want a userpage with something like "Hello {Username}, welcome to your homepage !. You're using this {email} right now."
What is the correct course of action ? As always, I've tried before asking. I navigate between overly complicated tutorials with notions I've never even seen or weird stuff that doesn't make any sense.
Here's the last try I've made :
- A DTO to expose only what's needed :
public record UserResponse(String email, String username) {
public static UserResponse from(User user) {
return new UserResponse(user.getEmail(), user.getUsername());
}
}