当前位置: 首页 > news >正文

OneCode 3.0 @FormAnnotation 注解速查手册

FormAnnotation 速查手册

注解概述

@FormAnnotation 是 OneCode 框架中用于配置表单组件的核心注解,允许开发者在代码中声明式地配置表单的各种属性,无需编写大量的 XML 或其他配置文件。

完整定义

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@BeanClass(clazz = CustomFormViewBean.class)
@Target({ElementType.TYPE})
public @interface FormAnnotation {ComponentType[] bindTypes() default {ComponentType.FormLayout, ComponentType.TreeView, ComponentType.Panel, ComponentType.Dialog};boolean floatHandler() default false;boolean autoLayout() default true;@NotNull boolean solidGridlines() default true;@NotNull int col() default 2;@NotNull int row() default 5;@NotNull FormLayModeType mode() default FormLayModeType.write;@NotNull StretchType stretchH() default StretchType.all;@NotNull StretchType stretchHeight() default StretchType.none;BorderType borderType() default BorderType.none;String background() default "#FFFFFF";OverflowType Overflow() default OverflowType.hidden;String showEffects() default "Flip V";String hideEffects() default "Flip V";int rowHeaderWidth() default -1;int columnHeaderHeight() default -1;int defaultRowSize() default -1;int defaultColumnSize() default -1;@NotNull int defaultRowHeight() default 35;int defaultColWidth() default 150;@NotNull int defaultLabelWidth() default 150;@NotNull int lineSpacing() default 10;@NotNull HAlignType textAlign() default HAlignType.center;CustomFormMenu[] customMenu() default {};CustomFormEvent[] event() default {};CustomFormMenu[] bottombarMenu() default {};Class[] customService() default {};
}

核心属性说明

1. 基础配置

  • bindTypes:绑定的组件类型,默认为表单布局、树形视图、面板和对话框
  • floatHandler:是否浮动表头,默认为 false
  • autoLayout:是否自动布局,默认为 true
  • solidGridlines:是否显示网格线,默认为 true
  • col:列数,默认为 2
  • row:行数,默认为 5

2. 布局模式

  • mode:表单布局模式,默认为写入模式
  • stretchH:水平拉伸类型,默认为全部拉伸
  • stretchHeight:垂直拉伸类型,默认为不拉伸
  • borderType:边框类型,默认为无边框
  • background:背景颜色,默认为白色
  • Overflow:溢出处理方式,默认为隐藏

3. 尺寸设置

  • rowHeaderWidth:行标题宽度,默认为 -1(自动)
  • columnHeaderHeight:列标题高度,默认为 -1(自动)
  • defaultRowSize:默认行大小,默认为 -1(自动)
  • defaultColumnSize:默认列大小,默认为 -1(自动)
  • defaultRowHeight:默认行高,默认为 35
  • defaultColWidth:默认列宽,默认为 150
  • defaultLabelWidth:默认标签宽度,默认为 150
  • lineSpacing:行间距,默认为 10
  • textAlign:文本对齐方式,默认为居中

4. 特效与交互

  • showEffects:显示特效,默认为 “Flip V”
  • hideEffects:隐藏特效,默认为 “Flip V”

5. 菜单与事件

  • customMenu:自定义菜单,默认为空数组
  • event:事件,默认为空数组
  • bottombarMenu:底部栏菜单,默认为空数组
  • customService:自定义服务类,默认为空数组

枚举类型解释

1. ComponentType

  • FormLayout:表单布局
  • TreeView:树形视图
  • Panel:面板
  • Dialog:对话框

2. FormLayModeType

  • design:设计模式
  • read:只读模式
  • write:可读写
  • none:默认

3. StretchType

  • none:默认
  • last:延申最后一行
  • all:平均分配

4. BorderType

  • none:无边框
  • flat:扁平边框
  • inset:内嵌边框
  • outset:外凸边框

5. OverflowType

  • visible:显示溢出内容
  • hidden:隐藏溢出内容
  • scroll:始终显示滚动条
  • auto:自动显示滚动条
  • overflowX:水平方向隐藏,垂直方向自动
  • overflowY:水平方向自动,垂直方向隐藏

6. HAlignType

  • left:左对齐
  • center:居中对齐
  • right:右对齐

7. CustomFormMenu

  • RELOAD:刷新菜单
  • SAVE:保存菜单
  • SAVEANACLOSE:保存并关闭菜单
  • SUBMITFORM:提交表单菜单
  • CLOSE:关闭菜单
  • CLOSETOP:关闭顶层菜单
  • SEARCH:查找菜单
  • RESET:重置菜单
  • PRINT:打印菜单

适用场景

@FormAnnotation 适用于以下场景:

  1. 企业级应用中的数据录入表单
  2. 管理后台的配置页面
  3. 工作流中的审批表单
  4. 数据查询和筛选界面
  5. 复杂业务逻辑的分步表单

使用示例

示例1: 基本表单配置

@FormAnnotation(bottombarMenu = {CustomFormMenu.SAVE, CustomFormMenu.CLOSE},col = 3,row = 10,mode = FormLayModeType.edit,borderType = BorderType.solid
)
public class MyFormClass {// 表单字段定义@FormFieldAnnotation(label = "用户名", required = true)private String username;@FormFieldAnnotation(label = "密码", required = true, password = true)private String password;@FormFieldAnnotation(label = "邮箱")private String email;
}

示例2: 只读表单配置

@FormAnnotation(mode = FormLayModeType.read,col = 2,row = 8,borderType = BorderType.none,solidGridlines = false
)
public class ReadOnlyFormClass {@FormFieldAnnotation(label = "订单编号")private String orderId;@FormFieldAnnotation(label = "订单金额")private BigDecimal amount;@FormFieldAnnotation(label = "下单时间")private Date orderTime;
}

示例3: 高级表单配置

@FormAnnotation(bottombarMenu = {CustomFormMenu.SAVE, CustomFormMenu.ADD, CustomFormMenu.DELETE},col = 2,row = 15,mode = FormLayModeType.write,borderType = BorderType.dashed,background = "#F5F5F5",defaultRowHeight = 40,defaultColWidth = 200,textAlign = HAlignType.left,customService = {FormValidationService.class}
)
public class AdvancedFormClass {// 表单字段定义
}

最佳实践

  1. 合理设置 colrow 以适应表单内容
  2. 根据需要选择合适的 mode(写入/只读/编辑)
  3. 对于复杂表单,考虑使用 autoLayout 自动布局
  4. 适当设置 defaultRowHeightdefaultColWidth 以提高表单可读性
  5. 合理配置菜单和事件以提升用户体验

注意事项

  1. 确保 bindTypes 包含了您要绑定的组件类型
  2. 对于大型表单,关闭 solidGridlines 可以提高性能
  3. 特效可能会影响性能,请谨慎使用
  4. 确保自定义服务类实现了必要的接口
http://www.lryc.cn/news/596040.html

相关文章:

  • 漫画版:细说金仓数据库
  • Qt/C++源码/监控设备模拟器/支持onvif和gb28181/多路批量模拟/虚拟监控摄像头
  • 秋招Day17 - Spring - AOP
  • 《基于蛋白质组学的精准医学》:研究进展与未来展望
  • 双指针算法介绍及使用(上)
  • GitHub 上的开源项目 ticktick(滴答清单)
  • MSTP技术
  • 【加解密与C】Rot系列(四)RotSpecial
  • 解决http下浏览器无法开启麦克风问题
  • haproxy七层均衡
  • n1 armbian docker compose 部署aipan mysql
  • 理解后端开发中的API设计原则
  • 清华大学顶刊发表|破解无人机抓取与投递难题
  • 第三章 Freertos物联网实战esp8266模块
  • LIMO:仅需817样本激活大模型数学推理能力,挑战“数据规模至上”传统范式
  • 从零构建智能对话助手:LangGraph + ReAct 实现具备记忆功能的 AI 智能体
  • MatterPort3D 数据集 | 简介 | 多途径下载
  • 低成本、高泛化能力的无人机自主飞行!VLM-Nav:基于单目视觉与视觉语言模型的无地图无人机导航
  • 基于模拟的流程为灵巧机器人定制训练数据
  • 动漫短剧系统开发全流程解析:从创意到上线的技术实践
  • CSS中的transform
  • 力扣面试150题--寻找峰值
  • Numpy的应用-2
  • 2025年远程桌面软件深度评测:ToDesk、向日葵、TeamViewer全方位对比分析
  • oracle查询数据结构滤涉及的sql语句
  • 开发者的AI认知指南:用大模型重新理解人工智能(下)
  • 疯狂星期四文案网第15天运营日记
  • PCIe Base Specification解析(三)
  • TDengine时序数据库 详解
  • Kotlin介绍