【问题标题】:I need help to display the id of a table but i'm having its memory address我需要帮助来显示表的 ID,但我有它的内存地址
【发布时间】:2020-10-22 21:10:42
【问题描述】:

我在 ordinateur 中有 2 个类 ordinateur 和 salle 由 ManyToOne 映射,我想在 ordinateur 表中显示到 salles 的 id,但我得到的是 salle 的内存地址

    This is the mapping in the ordinateur class
    @ManyToOne
        @JoinColumn(name="code_salle")
        private Salle salle;
        
        public Salle getSalle() {
            return salle;
        }
     and here where i want to display it 
    <h:column>
                    <f:facet name="header">Code de la salle</f:facet>
                    <h:outputText value="#{ordinateur.salle}"></h:outputText>
                </h:column>

【问题讨论】:

    标签: jpa jsf el


    【解决方案1】:

    您的 EL 表达式引用了 ordinateur 中的 salle 属性,因此,您将获得 Salle 对象。 EL 将在对象上调用toString(),这就是您看到的输出。你需要输出的是#{ordinateur.salle.id}

    顺便说一句,您看到的不是内存地址,而是类名和对象的哈希码。查看默认的toString() 实现:

    public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多