快速了解Urule Pro 库文件

1.之前我们讲了Urule的快速初始化

https://blog.csdn.net/liuchao_123456/article/details/129197082?spm=1001.2014.3001.5502

2.现在我们来了解一下Urule的库文件 [变量库、常量库、参数库、动作库]

我们可以鼠标右击选中 “库”,右边会出现【添加变量库、常量库、参数库、动作库】的选项

2.1 点击添加变量库->添加变量->添加字段

但这样一个一个添加变量字段会很麻烦,Urule提供了根据类路劲自动生成字段的功能。

我们可以这样操作,在代码中写一个类:

package com.bstek.demo.urule.entity;

import com.bstek.urule.model.Label;
import lombok.Data;

import java.math.BigDecimal;

@Data //必须提供get、set方法
public class Employee {
    @Label("编号") //@Label 对应页面上的字段名称
    private long id;
    @Label("姓名")
    private String name;
    @Label("标签")
    private String title;
    @Label("性别")
    private String sex;
    @Label("年龄")
    private Integer age;
    @Label("地址")
    private String address;
    @Label("电话")
    private String phone;
    @Label("地区得分")
    private BigDecimal areaScore;
    @Label("员工评级")
    private String employeErate;
    @Label("最终评分")
    private BigDecimal finalScore;

}

然后选中该变量,右击选择 根据类路劲生成字段,就会自动生成好java实体类对应的属性字段了。

2.2 点击添加常量库

Date

时间类型,输入时间格式有:yyyy-MM-dd HH:mm:ss、yyyy-MM-dd HH:mm、yyyy-MM-dd

List

ArrayList集合,值的设置方式为:

基础类型集合:s4,s1,s2,s3

复杂类型集合:[{"id":"4","name":"user4"},{"id":"1","name":"user1"}]

Set

TreeSet集合,值的设置方式为:

基础类型集合:s8,s5,s6,s7

复杂类型集合:[{"a1":"s8"},{"a1":"s5"},{"a1":"s6"},{"a1":"s7"}]

Map

HashMap集合,值的设置方式为:JSON格式,比如:{"a":"1","b":"2","c":"3"}

Enum

任意值

2.3 点击添加参数库

参数库选择数据类型时是可以选择变量库中的变量,如图我选择的数据类型为员工

2.4 添加动作库

首先需要在代码中添加一个方法类,然后在Urule页面上右击选中选择方法,双击选中你要添加的方法

当然urule中自带了很多方法,能满足大多数的设计需求,若urule自带的方法无法满足时可以添加自己的方法。

package com.bstek.demo.urule.test;
import java.lang.reflect.Member;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.bstek.urule.model.ExposeAction;
import org.springframework.stereotype.Component;

@Component //必须配置到spring中,让其成为一个标准的bean
public class MethodTest {

    @ExposeAction("helloKey") //@ExposeAction对应页面上显示时的名称
    public String hello(String username){
        System.out.println("hello "+username);
        return "hello"+username;
    }
    @ExposeAction("方法1")
    public boolean evalTest(String username){
        if(username==null){
            return false;
        }else if(username.equals("张三")){
            return true;
        }
        return false;
    }

    @ExposeAction("测试Int")
    public int testInt(int a,int b){
        return a+b;
    }
    public int testInteger(Integer a,int b){
        return a+b*10;
    }

    @ExposeAction("打印内容")
    public void printContent(String username,Date birthday){
        SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(birthday!=null){
            System.out.println(username+"今年已经"+sd.format(birthday)+"岁了!");
        }else{
            System.out.println("Hello "+username+"");
        }
    }
    @ExposeAction("打印Member")
    public void printUser(Member m){
        System.out.println("Hello "+m.getName()+", has house:"+m.isSynthetic());
    }

    @ExposeAction("是否能整除")
    public Boolean test4and6(int a,int b){
        if(b==0) return false;
        if(a%b==0) return true;
        return false;
    }
}

2.5自定义内置动作

package com.bstek.urule.runtime.builtinaction;
import com.bstek.urule.model.library.action.annotation.ActionBean;
import com.bstek.urule.model.library.action.annotation.ActionMethod;
import com.bstek.urule.model.library.action.annotation.ActionMethodParameter;
/**
 * @author Jacky.gao
 * @since 2015年11月27日
 */
@ActionBean(name="字符串")
public class StringAction {
    @ActionMethod(name="去空格")
    @ActionMethodParameter(names={"目标字符串"})
    public String trim(String str){
        if(str==null){
            return str;
        }
        return str.trim();
    }

    @ActionMethod(name="指定起始的字符串截取")
    @ActionMethodParameter(names={"目标字符串","开始位置","结束位置"})
    public String substring(String str,int start,int end){
        return str.substring(start, end);
    }
    ......
}

总结:

库文件中存放的是规则设计中用到的变量和方法,相当于规则设计的必要工具,可以理解为java中写接口时需要用到的实体类和工具包,给后面规则设计的时候使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值