I have a project where on the frontend you select from options, Easy medium and hard and on the backend I have a enum that represents the same data. When I save the data to the database it saves in correctly, difficulty will be EASY, MEDIUM or HARD, but when I fetch the data to display it on the frontend the difficulty value may say MEDIUM but if I compare it to the string MEDIUM so i can conditionally apply some CSS they are not the same type. Is this because an enum is really a string and when I make the comparison its always false cause the types are different?
@Enumerated(EnumType.STRING)
private Difficulty difficulty;
public enum Difficulty {
EASY("easy"),
MEDIUM("medium"),
HARD("hard");
private String difficulty;
Difficulty(String difficulty) {
this.difficulty = difficulty;
}
public String getDifficulty() {
return difficulty;
}
public void setDifficulty(String difficulty) {
this.difficulty = difficulty;
}
}
<th:block th:switch="${build.difficulty}">
<span class="badge rounded-pill text-bg-success" th:case="EASY" th:text="${build.difficulty}"></span>
<span class="badge rounded-pill text-bg-warning" th:case="MEDIUM" th:text="${build.difficulty}"> </span>
<span class="badge rounded-pill text-bg-danger" th:case="HARD" th:text="${build.difficulty}"></span>
</th:block>