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
      • The basic example
      • Nested with THEN, WHEN
      • Id syntax in switch
    • 🌵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文档
  • 🧩How to write EL rules
铂赛东
2022-06-29
Contents

🌾Switch mode

When we write business logic, we usually encounter the problem of selectivity, that is, if the result 1 is returned, the A process is entered, if the result 2 is returned, the B process is entered, and if the result 3 is returned, the C process is entered. It is also defined as an exclusive gateway in some process definitions.

This expression via LiteFLow is also very easy to implement. You can use the combination of SWITCH...to keywords. Note that SWITCH must be uppercase and to lowercase.

# The basic example

If you choose to execute one of b, c, and d according to component a, you can declare it as follows:

<chain name="chain1">
    SWITCH(a).to(b, c, d);
</chain>

Flow chart

# Nested with THEN, WHEN

We combine the previous two chapters to see some examples by nesting the three expressions

<chain name="chain1">
    THEN(
        a,
        WHEN(
            b,
            SWITCH(c).to(d,e)
        ),
        f
    );
</chain>

Flow chart

# Id syntax in switch

Next, an example of THEN and WHEN in SWITCH is shown.

If you've read the chapter Switch Components, you should know that LiteFlow determines what to select by returning a switch result.

So if there is a THEN in SWITCH, what should the switch component return if you want to select this THEN?

It is stipulated in LiteFlow that each expression can have an id value, and you can set the id value to set the id value of an expression. Then return this id in the switch component. The usage is as follows:

<chain name="chain1">
    THEN(
        a,
        SWITCH(b).to(
            c, 
            THEN(d, e).id("t1")
        ),
        f
    );
</chain>

Flow chart

If you want to select the expression THEN, then you can return t1 in the switch component:

@LiteflowComponent("b")
public class BCmp extends NodeSwitchComponent {

    @Override
    public String processSwitch() throws Exception {
        //do your biz
        return "t1";
    }
}
Help us improve this document (opens new window)
last update: 2022/10/13, 00:02:27
🎋Parallel mode
🌵If mode

← 🎋Parallel mode 🌵If mode→

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