匿名函数托管器|匿名函数托管器 spring-boot-func-starter
spring-boot-func-starter
spring-boot-func-starter 介绍
项目地址: https://gitee.com/yiur/spring-boot-func-starter
【匿名函数托管器|匿名函数托管器 spring-boot-func-starter】基于SpringBoot的匿名函数托管器,在springboot中可以将接口的方法进行各种操作
平时的java开发中继承接口要将接口的方法全实现,而func匿名函数托管不需要进行全部
实现可以用@FuncLambda
进行单独实现,没有进行匿名实现的接口方法不能进行调用,
func匿名函数还可以动态实现接口方法,配合代码达到更多操作,此外还有函数回调的
功能,在web开发中使用func匿名函数的对象是默认调用回调方法的,你也可以通过继承
Callback
接口编写自己想要的(then, error)回调方法
error
目前不兼容springboot的热部署
注解模式开发 项目搭建@FuncConfiguration
匿名配置
@FuncLambda
匿名函数配置
定义接口,此接口的方法由匿名函数代理
public interface WebInitOutInfo {String out(String message, String... args);
}
@FuncConfiguration
匿名函数的总配置@FuncLambda
匿名函数classFile
代理的接口funcCallback
回调函数callbackClass
绑定的回调函数类
@FuncConfiguration
public class WebFuncLinkConfig {@FuncLambda(classFile = WebInitOutInfo.class,
funcCallback = @FuncCallback(callbackClass = BlogCallback.class))
public String out(@FuncParameter("message") String message, @FuncParameter("args") String... args) {
return FuncString.format(message, args);
}}
回调函数实现
Callback
接口即可public class BlogCallback implements Callback {@Override
public Object then(Object o) {
return FuncString.format("then blogCallBack:value(?)", o);
}@Override
public Object error(Exception e) {
return ((InvocationTargetException)e).getTargetException().getMessage();
}}
启动类开启匿名函数自动装配
@EnableFuncLambda
@EnableWebMvc
@EnableFuncLambda
@SpringBootApplication
public class WebBlogApplication {public static void main(String[] args) {
SpringApplication.run(WebBlogApplication.class, args);
}}
配置web进行测试,编写controller
@Controller
public class BlogController {@Autowired
public WebInitOutInfo webInitOutInfo;
@ResponseBody
@RequestMapping("/replace")
public String value(String message, String... args) {
return webInitOutInfo.out(message, args);
}}
测试成功回调[http://localhost:8888/replace?message=value ? ?&args=12, hello func](http://localhost:8888/replace?message=value ? ?&args=12, hello func)
文章图片
测试失败回调[http://localhost:8888/replace?message=value ? ??&args=12,%20hello%20func](http://localhost:8888/replace?message=value ? ??&args=12, hello func)
文章图片
推荐阅读
- 一起来学习C语言的字符串转换函数
- C语言字符函数中的isalnum()和iscntrl()你都知道吗
- C语言浮点函数中的modf和fmod详解
- C语言中的时间函数clock()和time()你都了解吗
- 概率论/统计学|随机变量 的 分布函数 与 概率密度函数 的区别
- vue组件中为何data必须是一个函数()
- iOS-Swift-map|iOS-Swift-map filter reduce、函数式编程
- R语言|R语言 函数
- 2018-05-30闭包和函数
- 函数的一些东西