模块“市”的设计与增加
如今反复增加“省”模块的过程,来增加市的模块。1、建立数据表CityCREATE TABLE [dbo].[City]( [tf_cityId] [nvarchar](4) COLLATE Chinese_PRC_CI_AS NOT NULL, [tf_provinceId] [nvarchar](2) COLLATE Chinese_PRC_CI_AS NOT NULL, [tf_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, [tf_postNumber] [nvarchar](6) COLLATE Chinese_PRC_CI_AS NULL, [tf_telHead] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL, [tf_money] [money] NOT NULL CONSTRAINT [DF_City_tf_money] DEFAULT ((0)), [tf_remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT [PK_City] PRIMARY KEY CLUSTERED ( [tf_cityId] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] ALTER TABLE [dbo].[City] WITH CHECK ADD CONSTRAINT [FK_City_Province] FOREIGN KEY([tf_provinceId]) REFERENCES [dbo].[Province] ([tf_provinceId]) ON UPDATE CASCADE*对市名称建立唯一索引 CREATE UNIQUE NONCLUSTERED INDEX [IX_City] ON [dbo].[City] ( [tf_name] ASC )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
2、建立hibernate Bean: City.javapackage com.jfok.server.hibernate.sales; import java.io.Serializable; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import org.codehaus.jackson.map.annotate.JsonSerialize; import com.jfok.server.common.annotation.FieldDefine; import com.jfok.server.common.annotation.TableDefine; @Entity @SuppressWarnings("serial") @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) @org.hibernate.annotations.Entity(dynamicUpdate = true) @TableDefine(group = "编码设置", id = 7012, title = "市") public class City implements Serializable { @Id @FieldDefine(title = "编码", number = 10, fieldGroup = "基本信息") @Column(nullable = false, length = 4) // 所有的数据表字段,所实用tf_开头,仅仅是为了好分别表字段还是普通bean字段而己 private String tf_cityId; // manyToOne 定义了此模块的一个父模块。不用在Province定义oneToMany了,这里的父子关系是双向的。 @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER) @JoinColumn(name = "tf_provinceId", nullable = false) @FieldDefine(title = "省份", number = 20, fieldGroup = "基本信息") private Province tf_Province; @FieldDefine(title = "名称", number = 30, nameField = true, fieldGroup = "基本信息") @Column(nullable = false, length = 50, unique = true) private String tf_name; @FieldDefine(title = "邮政编码", number = 40, fieldGroup = "附加信息") @Column(length = 6) private String tf_postNumber; @FieldDefine(title = "电话区号", number = 50, fieldGroup = "附加信息") @Column(length = 6) private String tf_telHead; // 此字段无实际意义,仅仅是为了某些功能的展示所用 @FieldDefine(title = "金额属性", number = 70, fieldGroup = "附加信息") private Double tf_money = 0.0; @FieldDefine(title = "备注", number = 190, fieldGroup = "附加信息") private String tf_remark; public City() { } //setter and getter
3、在配置文件hibernate.cfg.xml中增加<mapping class="com.jfok.server.hibernate.sales.City" />
至此编码阶段就完毕了,以下要做的就是将模块导入系统,然后进行配置了。
4、导入模块“市”。进入“模块管理”,按导入模块button。
确定后,将会导入City模块,模块字段,生成缺省的grid和form。
以下看一下导入的City的字段。
如今展示一下省份这个manyToOne字段的属性。
5、给City模块增加角色操作权限;6、将City模块增加到菜单。上二个步骤參见前面模块“省”操作。
至此一个新的模块City增加成功。