首页 > 解决方案 > 如何在 Jhipster 的前端使用 HashMap?

问题描述

我正在开发一个 Jhipster 应用程序,其中我有一个带有Map<String, String>, 在后端的实体一切正常。但我不知道如何在实体详细信息视图中显示地图,因为 jhipster 不会向我生成它,我必须手动完成。

我从角度开始,我不知道如何在 html 中声明地图entity.model.ts或如何在 html 中进行迭代。

实体.java

....Other attributes....

    @ElementCollection(fetch=FetchType.EAGER)
    @MapKeyColumn(name="key")
    @Column(name="value")
    @CollectionTable(name="map", joinColumns=@JoinColumn(name="entity_id"))
    private Map<String, String> map= new HashMap<>();

....getters and setters....

实体模型.ts

export class entity implements BaseEntity {
    constructor(
        public id?: number,
        public name?: string,
    ) {
    }
}

实体-view.component.html

<div class="modal-body">
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
            <tr>
                <th><span>Key</span></th>
                <th><span>Value</span></th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let map of entity.map">
                <td><span>{{map.key}}</span></td>
                <td><span>{{map.value}}</span></td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

标签: javahtmlangularspring-bootjhipster

解决方案


推荐阅读