最简单的方式,是适合于POJO的需求,通过Annotation的方式来实现。
具体可以参见下面的代码范例:
@ReportClass( title = "Users", reportSheets = { @ReportSheet( freezed = 1, index = false, sheetName = "User", reportPrimitiveFields = {@ReportPrimitiveField(fieldName="email",width=20), @ReportPrimitiveField(fieldName="name",width=15, url="http://localhost:8080/vaalhaai/framework/identityUserAction!open.do?id=${id}"), @ReportPrimitiveField(fieldName="loginId",width=20), @ReportPrimitiveField(fieldName="nickName") } ), @ReportSheet( freezed = 2, index = true, sheetName = "All", reportPrimitiveFields = {@ReportPrimitiveField(fieldName="email",width=20), @ReportPrimitiveField(fieldName="name",width=15), @ReportPrimitiveField(fieldName="loginId",width=20), @ReportPrimitiveField(fieldName="nickName",width = 20), @ReportPrimitiveField(fieldName="password",width = 10) }, reportEntityCollectionFields = { @ReportEntityCollectionField( className="com.vaalhaai.framework.identity.entity.Group", sheetName="Group", fieldName="groups") } ) } ) public class User extends BaseEntity { private static final long serialVersionUID = 83202417663407938L; /** password */ @Column(name = "PASSWORD") @Size(min = 6, max = 128) private String password; /** login id */ @Column(name = "LOGIN_ID", unique = true) @Index(name = "FRAMEWORK_IDENTITY_USER_LOGINID", columnNames = "LOGIN_ID") @Size(min = 5, max = 50) private String loginId; /** email */ @Column(name = "EMAIL") @Email @Size(max = 50) private String email; /** birthday */ @Column(name = "BIRTHDAY") @Temporal(TemporalType.DATE) private Date birthday; /** gender */ @Column(name = "GENDER") @Size(max = 10) private String gender; @Column(name = "NICK_NAME") @Size(max = 50) private String nickName; @Column(name = "CELLPHONE") @Size(max = 50) private String cellphone; @Column(name = "TELEPHONE") @Size(max = 50) private String telephone; @ManyToMany(cascade = { CascadeType.ALL }) @JoinTable(name = "VAALHAAI_IDENTITY_USER_REF_GROUP", joinColumns = { @JoinColumn(name = "GROUP_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") }) private Set<Group> groups = new HashSet<Group>(); public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getLoginId() { return loginId; } public void setLoginId(String loginId) { this.loginId = loginId; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } /* * public void setBirthday(String birthday) throws ParseException { * this.birthday = DateUtil.parseDate(birthday); } */ public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getNickName() { return nickName; } public void setNickName(String nickName) { this.nickName = nickName; } /** * @return the cellphone */ public String getCellphone() { return cellphone; } /** * @param cellphone * the cellphone to set */ public void setCellphone(String cellphone) { this.cellphone = cellphone; } /** * @return the groups */ public Set<Group> getGroups() { return groups; } /** * @param groups * the groups to set */ public void setGroups(Set<Group> groups) { this.groups = groups; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((loginId == null) ? 0 : loginId.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; User other = (User) obj; if (loginId == null) { if (other.loginId != null) return false; } else if (!loginId.equals(other.loginId)) return false; return true; } }
定义可以在Annotation上面完成。
至于对于标题的中文支持,可以通过国际化的方式来实现。
User = 用户 name = 姓名 loginId = 登录名 password = 密码 email = 邮箱 birthday = 出生日期 gender = 性别 nickName = 别名 cellphone = 手机 telephone = 电话 groups = 群组 #报表 Users = 用户 All = 所有信息
如果你不喜欢用Annotation的方式,那就期待下一个版本吧,会支持使用数据库定制的方式!