1.7.3.1. 创建一个实体
创建一个 CountryGrowth
实体类。
-
在 CUBA 项目树的 Data Model 部分,单击 New → Entity。 将弹出 New CUBA Entity 对话框窗口。
-
在 Entity name 字段中输入实体类的名称 –
CountryGrowth
,选择 Entity type 为Not persistent
,然后点击 OK 按钮。实体设计器界面将显示在工作区。 -
使用 Entity Designer 添加如下属性:
-
country
,类型是String
-
year2014
,类型是Double
-
year2015
,类型是Double
-
-
切换到 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
实体类就创建完成了。