当前位置: 首页 > news >正文

spring常用语法


etl表达式解析

if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {
   // assume it's spel
   StandardEvaluationContext context = new StandardEvaluationContext();
   context.setBeanResolver(new BeanFactoryResolver(beanFactory));
   Expression expression = parser.parseExpression(entryValue,
         new TemplateParserContext());
   value = expression.getValue(context);
}

属性绑定
Bindable<T> bindable = Bindable.of(this.configurable.getConfigClass());T t =new Binder(propertySources, null, conversionService).bindOrCreate(configurationPropertyName, bindable, handler);

 ApplicationContext context = SpringApplication.run(Application.class, args);
 
        Binder binder = Binder.get(context.getEnvironment());


绑定简单配置 

  FooProperties foo = binder.bind("com.didispace", Bindable.of(FooProperties.class)).get();
        System.out.println(foo.getFoo());
  

绑定List配置

      List<String> post = binder.bind("com.didispace.post", Bindable.listOf(String.class)).get();
        System.out.println(post);
 
        List<PostInfo> posts=binder.bind("com.didispace.posts",Bindable.listOf(PostInfo.class)).get();
        System.out.println(posts);
        // 读取配置       System.out.println(context.getEnvironment().containsProperty("com.didispace.database-platform"));
  System.out.println(context.getEnvironment().containsProperty("com.didispace.databasePlatform"));

配置绑定到Map对象
Map<String, DsConfig> dsMap = binder.bind("demo.dynamic", Bindable.mapOf(String.class, DsConfig.class)).get();
System.out.println("Map Config: " + dsMap);
配置转换处理

  

String decPwd = binder.bind("demo.enc.pwd", Bindable.of(String.class)).map(s -> new String(Base64Utils.decodeFromString(s))).get();
System.out.println("解码之后的数据是: " + decPwd);
注册绑定过程回调


String dec = binder.bindOrCreate("demo.enc.pwd", Bindable.of(String.class), new BindHandler() {
    @Override
    public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) {
        System.out.println("开始绑定: " + name);
        return BindHandler.super.onStart(name, target, context);
    }

    @Override
    public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
        System.out.println("绑定成功!" + name + " val:" + target.getValue() + " res: " + result);
        return new String(Base64Utils.decodeFromString((String) result));
    }

    @Override
    public Object onCreate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
        System.out.println("创建: " + name + " val:" + target.getValue() + " res: " + result);
        return BindHandler.super.onCreate(name, target, context, result);
    }

    @Override
    public Object onFailure(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Exception error) throws Exception {
        System.out.println("绑定失败! " + name + "  " + error.getMessage());
        return BindHandler.super.onFailure(name, target, context, error);
    }

    @Override
    public void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception {
        System.out.println("绑定结束: " + name + " val:" + target.getValue() + " res: " + result);
        BindHandler.super.onFinish(name, target, context, result);
    }
});
System.out.println("绑定回调: " + dec);

http://www.lryc.cn/news/291960.html

相关文章:

  • 【计算机毕业设计】128电脑配件销售系统
  • 换个思维方式快速上手UML和 plantUML——类图
  • 策略模式+SpringBoot接口,一个接口实现接收的数据自动分流处理
  • P1228 地毯填补问题(葬送的芙蓉王【bushi】)
  • 352. 闇の連鎖(树上差分,LCA)
  • dcat admin + dingo + nginx 开发前台
  • 安卓线性布局LinearLayout
  • Advanced CNN
  • 判断当前设备是不是安卓或者IOS?
  • 使用C++操作Matlab中的mat文件
  • 【OCPP】ocpp1.6协议第3.5章节:本地授权和离线行为-介绍及翻译
  • OpenGL查询对象 Query Objects
  • 【数据分享】1929-2023年全球站点的逐日最高气温数据(Shp\Excel\免费获取)
  • Docker深入解析:从基础到实践
  • 【鸿蒙】大模型对话应用(一):大模型接口对接与调试
  • SQL的函数类型
  • TSINGSEE青犀视频智慧电梯管理平台,执行精准管理、提升乘梯安全
  • VMware:在部分链上无法执行所调用的函数,请打开父虚拟磁
  • 【数据结构 08】红黑树
  • 【百度Apollo】自动驾驶规划技术:实现安全高效的智能驾驶
  • 《C程序设计》上机实验报告(五)之一维数组二维数组与字符数组
  • 【BUG】联想Y7000电池电量为0且无法充电解决方案汇总
  • centos7常用命令之安装插件2
  • MATLAB - 仿真单摆的周期性摆动
  • Pandas进阶--map映射,分组聚合和透视pivot_table详解
  • Visual Studio 和Clion配置Cocos2d-x环境
  • 【百度Apollo】本地调试仿真:加速自动驾驶系统开发的利器
  • ztest中ddof起什么作用
  • linux 主机无法联网问题
  • 2024/1/27 备战蓝桥杯 1-1