1.@interface自定义注解 <1>@interface自定义注解自动继承了java.lang.annotation.Annotation接口,由编译程序自动完成其他细节。 <2>在定义注解时,不能继承其他的注解或接口。 <3>使用@interface来声明一个注解, 1>.每一个方法实际上是声明了一个配置参数, 2>.方法的名称就是参数的名称, 3>.返回值类型就是参数的类型,(返回值类型只能是基本类型、Class、String、enum) 4>.可以通过default来声明参数的默认值
package com.xsz.common.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.apache.poi.hssf.util.HSSFColor; /** * Excel导出项配置 */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.FIELD }) public @interface ExportConfig { /** * @return 表头显示名(如:id字段显示为"编号") 默认为字段名 */ String value() default "field"; /** * @return 单元格宽度 默认-1(自动计算列宽) */ short width() default -1; /** * 将单元格值进行转换后再导出:<br/> * 目前支持以下几种场景:<br/> * 1. 固定的数值转换为字符串值(如:1代表男,2代表女)<br/> * <b>表达式:</b> "s:1=男,2=女"<br/> * * 2. 数值对应的值需要查询数据库才能进行映射(实现com.xsz.util.poi.convert.ExportConvert接口)<br/> * * @return 默认不启用 */ String convert() default ""; /** * @return 当前单元格的字体颜色 (默认 HSSFColor.BLACK.index) */ short color() default HSSFColor.BLACK.index; /** * 将单元格的值替换为当前配置的值:<br/> * 应用场景: <br/> * 密码字段导出为:"******" * * @return 默认true */ String replace() default ""; }
package com.xsz.system.domain; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import com.xsz.common.annotation.ExportConfig; @Table(name = "t_menu") public class Menu implements Serializable { private static final long serialVersionUID = 7187628714679791771L; public static final String TYPE_MENU = "0"; public static final String TYPE_BUTTON = "1"; @Id @GeneratedValue(generator = "JDBC") @Column(name = "MENU_ID") @ExportConfig(value = "编号") private Long menuId; @Column(name = "PARENT_ID") private Long parentId; @Column(name = "MENU_NAME") @ExportConfig(value = "名称") private String menuName; @Column(name = "URL") @ExportConfig(value = "地址") private String url; @Column(name = "PERMS") @ExportConfig(value = "权限标识") private String perms; @Column(name = "ICON") @ExportConfig(value = "图标") private String icon; @Column(name = "TYPE") @ExportConfig(value = "类型", convert = "s:0=菜单,1=按钮") private String type; @Column(name = "ORDER_NUM") private Long orderNum; @Column(name = "CREATE_TIME") @ExportConfig(value = "创建时间", convert = "c:com.xsz.common.util.poi.convert.TimeConvert") private Date createTime; @Column(name = "MODIFY_TIME") private Date modifyTime; /** * @return MENU_ID */ public Long getMenuId() { return menuId; } /** * @param menuId */ public void setMenuId(Long menuId) { this.menuId = menuId; } /** * @return PARENT_ID */ public Long getParentId() { return parentId; } /** * @param parentId */ public void setParentId(Long parentId) { this.parentId = parentId; } /** * @return MENU_NAME */ public String getMenuName() { return menuName; } /** * @param menuName */ public void setMenuName(String menuName) { this.menuName = menuName == null ? "" : menuName.trim(); } /** * @return URL */ public String getUrl() { return url; } /** * @param url */ public void setUrl(String url) { this.url = url == null ? "" : url.trim(); } /** * @return PERMS */ public String getPerms() { return perms; } /** * @param perms */ public void setPerms(String perms) { this.perms = perms == null ? "" : perms.trim(); } /** * @return ICON */ public String getIcon() { return icon; } /** * @param icon */ public void setIcon(String icon) { this.icon = icon == null ? "" : icon.trim(); } /** * @return TYPE */ public String getType() { return type; } /** * @param type */ public void setType(String type) { this.type = type == null ? "" : type.trim(); } /** * @return ORDER_NUM */ public Long getOrderNum() { return orderNum; } /** * @param orderNum */ public void setOrderNum(Long orderNum) { this.orderNum = orderNum; } /** * @return CREATE_TIME */ public Date getCreateTime() { return createTime; } /** * @param createTime */ public void setCreateTime(Date createTime) { this.createTime = createTime; } /** * @return MODIFY_TIME */ public Date getModifyTime() { return modifyTime; } /** * @param modifyTime */ public void setModifyTime(Date modifyTime) { this.modifyTime = modifyTime; } }