0

如何将 Enum 的字符串值(密码)保存到数据库?现在我只能保存 Enum 类型 ( ID_CARD, INTERNATIONAL_PASSPORT)。

我的枚举类

public enum Citizen {

    ID_CARD("Id card"),
    INTERNATIONAL_PASSPORT("International passport"),
    FOREIGN_PASSPORT("Foreign passport");

    private String passport;

    private Citizen(String passport){
        this.passport = passport;
    }

    public String getPassport(){
        return passport;
    }
}

​</p>

@Entity
@Table(name = "citizen")
public class Client implements Serializable{

    @Id
    @Column(name = "inn")
    private long inn;
    @Enumerated(EnumType.STRING)
    @Column(name = "citizen")
    private Citizen citizen;
}

HTML页面:

<select th:field="${client.citizen}">
    <!--/*@thymesVar id="state" type=""*/-->
    <option th:each="state :   ${T(models.client.Citizen).getCitizens()}"
            th:value="${state}" th:text="${state}">
    </option>
</select>

我想保存 th:value="${state.passport}" th:text="${state.passport}"

4

0 回答 0