zoukankan      html  css  js  c++  java
  • @Value

    @Data
    @Component
    //可以通过@ConfigurationProperties来自动绑定
    //@ConfigurationProperties(prefix = "test2")
    @PropertySource({"classpath:test.properties"})
    public class SpELBean {
        // @Value 在spring包下, 必须将所在类注入到ioc中才会生效
        @Value("#{'老王'.concat('八')}")
        private String name;
        //调用注入到ioc中的bean, 支持三目运算
        @Value("#{spELBean.name.length()==3?-100:100}")
        private Integer age;
        // Elvis表达式, 与${}不同的是,${}使用Elvis表达式不用带?
        @Value("#{null?:100}")
        private Double score;
        @Value("#{'100kg'.toUpperCase()}")
        private String weight;
        /* 内置对象相当于
           system.getProperties*/
        @Value("#{systemProperties['user.dir']}")
        private String dir;
        //使用 T(...) 可以调用Jdk中的一些工具类的静态方法
        @Value("#{T(Math).random()*10}")
        private Double num;
        // T(...)对应Class类型
        @Value("#{T(Double)}")
        private Class<?> aClass;
        @Value("#{{'a','b','c'}}")
        private List<String> list1;
        //自定义的properties属性绑定list
        @Value("#{'${test2.list}'.split(',')}")
        private List<Integer> list3;
        //通过自定义的properties属性绑定map, key不带双引号
        @Value("#{${test2.map}")
        private Map<String, String> map;
    }
    
    test2.list=1,2,3,4,5
    #map的key不用带双引号
    test2.map={name:"张丹",age:12}
    
  • 相关阅读:
    iOS堆栈-内存-代码在据算机中的运行
    iOS self和super的区别
    php代码优化
    缓存雪崩现象解决方案
    缓存失效
    分布式memcache
    Linux下编译安装Memcache
    windows 下安装 php-memcached 扩展
    Linux下安装 php-memcache 扩展
    缓存之文件缓存
  • 原文地址:https://www.cnblogs.com/kikochz/p/12820822.html
Copyright © 2011-2022 走看看