2.6.3.1. 创建一个实体

创建一个 CountryGrowth 实体类。

  1. 在 CUBA 项目树的 Data Model 部分,单击 New → Entity。 将弹出 New CUBA Entity 对话框窗口。

  2. Entity name 字段中输入实体类的名称 – CountryGrowth,选择 Entity typeNot persistent,然后点击 OK 按钮。实体设计器界面将显示在工作区。

  3. 使用 Entity Designer 添加如下属性:

    • country,类型是 String

    • year2014,类型是 Double

    • year2015,类型是 Double

  4. 切换到 Text 标签页,这个标签页上显示 CountryGrowth 类的源代码。

    package com.company.sampler.entity;
    
    import com.haulmont.chile.core.annotations.MetaClass;
    import com.haulmont.chile.core.annotations.MetaProperty;
    import com.haulmont.cuba.core.entity.BaseUuidEntity;
    
    @MetaClass(name = "sampler_CountryGrowth")
    public class CountryGrowth extends BaseUuidEntity {
        @MetaProperty
        protected String country;
    
        @MetaProperty
        protected Double year2014;
    
        @MetaProperty
        protected Double year2015;
    
        public Double getYear2015() {
            return year2015;
        }
    
        public void setYear2015(Double year2015) {
            this.year2015 = year2015;
        }
    
        public Double getYear2014() {
            return year2014;
        }
    
        public void setYear2014(Double year2014) {
            this.year2014 = year2014;
        }
    
        public String getCountry() {
            return country;
        }
    
        public void setCountry(String country) {
            this.country = country;
        }
    }

    这个类是非持久化实体。这个类的一个实例包含一个国家 2014 和 2015 年的 GDP 增长率。

现在,CountryGrowth 实体类就创建完成了。