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}
    
  • 相关阅读:
    BZOJ2142: 礼物
    GYM100633J. Ceizenpok’s formula 扩展lucas模板
    Codeforces451E Devu and Flowers
    BZOJ2982: combination Lucas模板
    UVAL3700
    BZOJ2821: 作诗(Poetize)
    BZOJ2724: [Violet 6]蒲公英
    Luogu P1858 多人背包
    Luogu P2831 愤怒的小鸟(状压+记忆化搜索)
    Luogu P4205 [NOI2005]智慧珠游戏
  • 原文地址:https://www.cnblogs.com/kikochz/p/12820822.html
Copyright © 2011-2022 走看看