magic-api magic-api
首页
  • 快速入门
  • 基础教程
  • 权限配置
  • 高级应用
  • 开发插件
  • 模块
  • 函数
  • 扩展
  • Gitee (opens new window)
  • Github (opens new window)
  • 演示 (opens new window)
  • SpringBoot配置
  • 编辑器配置
  • 2.x更新日志
  • 1.x更新日志
  • 0.x更新日志
常见问题
💖支持
交流群
首页
  • 快速入门
  • 基础教程
  • 权限配置
  • 高级应用
  • 开发插件
  • 模块
  • 函数
  • 扩展
  • Gitee (opens new window)
  • Github (opens new window)
  • 演示 (opens new window)
  • SpringBoot配置
  • 编辑器配置
  • 2.x更新日志
  • 1.x更新日志
  • 0.x更新日志
常见问题
💖支持
交流群
  • 快速入门

    • 简介
    • 快速开始
    • 请求参数获取
    • 增删改查
    • 单表crud接口
    • 分页
  • 基础教程

    • 界面简介
    • 脚本语法
    • 配置多数据源
    • 统一请求响应
    • 统一异常处理
    • 参数校验
    • 脚本调用Java
    • Java调用接口
    • 异步调用
    • 接口发布
    • Lambda
    • Linq
    • 从1.x迁移
  • 权限配置

    • UI鉴权登录
    • UI操作鉴权
    • 接口鉴权
  • 高级应用

    • 自定义拦截器
    • 自定义SQL拦截器
    • 自定义单表API拦截器
    • 自定义SQL缓存
    • 自定义模块
    • 自定义函数
    • 自定义类型扩展
    • 自定义接口存储
    • 自定义数据库方言
    • 自定义列名转换
    • 自定义脚本语言
  • 插件

    • 插件开发
    • 集群插件
    • 定时任务插件
    • Redis插件
    • Mongo插件
    • ElasticSearch插件
    • Swagger插件
    • Git插件
  • 指南
  • 高级应用
mxd
2022-01-30

自定义函数

import org.ssssssss.script.annotation.Comment;
/**
 * 自定义函数
 */
@Component  //注入到Spring容器中
public class MyCustomFunction implements MagicFunction {
    
    // 脚本中直接使用 now();
    @Function
    @Comment("取当前时间")
    public static Date now() {
        return new Date();
    }
    // 脚本中使用 date_format(now())
    @Function
    @Comment("日期格式化")
    public static String date_format(@Comment("目标日期") Date target) {
        return target == null ? null : DateExtension.format(target, "yyyy-MM-dd HH:mm:ss");
    }

    // 脚本中使用 date_format(now(),'yyyy-MM-dd')
    @Function
    @Comment("日期格式化")
    public static String date_format(@Comment("目标日期") Date target, @Comment("格式") String pattern) {
        return target == null ? null : DateExtension.format(target, pattern);
    }

    // 脚本中直接使用ifnull() 调用
	@Function
    @Comment("判断值是否为空")
    public static Object ifnull(@Comment("目标值") Object target, @Comment("为空的值") Object trueValue, @Comment("不为空的值") Object falseValue) {
        return target == null ? trueValue : falseValue;
    }

}
上次更新: 2022-08-28 08:18:19
自定义模块
自定义类型扩展

← 自定义模块 自定义类型扩展→

Theme by Vdoing | Copyright © 2020-2023 ssssssss.org | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×