LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🍇Declarative component
铂赛东
2022-10-12

🥥Method level declaration

LiteFlow supports method-level declarative features since v2.9.0.

The method level declaration allows users to define multiple components in a class through annotations, which is more flexible.

If you have a lot of components and want to avoid the problem of having too many classes defined, then this feature is very suitable for this need.

You can define multiple components in a bean like this:

@LiteflowComponent
public class CmpConfig {

    //Definition of common components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
    public void processA(NodeComponent bindCmp) {
        ...
    }

    //Definition of switch components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "b", nodeType = NodeTypeEnum.SWITCH)
    public void processB(NodeComponent bindCmp) {
        ...
    }
    
    //Definition of if components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "c", nodeType = NodeTypeEnum.IF)
    public boolean processC(NodeComponent bindCmp) {
        ...
    }
    
    //Definition of for components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "d", nodeType = NodeTypeEnum.FOR)
    public int processD(NodeComponent bindCmp) {
        ...
    }
    
    //Definition of while components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "e", nodeType = NodeTypeEnum.WHILE)
    public int processE(NodeComponent bindCmp) {
        ...
    }
    
    //Definition of break components
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "f", nodeType = NodeTypeEnum.BREAK)
    public int processF(NodeComponent bindCmp) {
        ...
    }
}

notice1

It should be noted here that for the method-level declaration feature, the nodeId on the @LiteflowMethod annotation must be written.

The nodeType on the common component can be omitted because it has a default value, but for the sake of clarity, it is recommended that you add nodeType = NodeTypeEnum.COMMON.

notice2

When you define a method yourself, the return value should be the same as the return value of the corresponding method in the conventional component. For example, the process method of ordinary components does not return, such as the processIf method of IF components, which returns a boolean value.

If you write it wrong, a little exception will occur, which may increase your troubleshooting time.

The methods for other components are also declared in a similar way. For example, I define 2 components in a class, and each component implements 3 methods, which can be written as follows:

@LiteflowComponent
public class CmpConfig {

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
    public void processA(NodeComponent bindCmp) {
        ...
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
    public boolean isAccessA(NodeComponent bindCmp){
        ...
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
    public void onSuccessA(NodeComponent bindCmp){
        ...
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF)
    public boolean processF(NodeComponent bindCmp) {
        ...
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "f", nodeType = NodeTypeEnum.IF)
    public boolean isAccessF(NodeComponent bindCmp){
        ...
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "f", nodeType = NodeTypeEnum.IF)
    public void onSuccessF(NodeComponent bindCmp){
        ...
    }
}
Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🧅Class level declaration
🍄Notice

← 🧅Class level declaration 🍄Notice→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式