@value注解
该注解的作用是将我们配置文件的属性读出来,有@Value(“${}”)和@Value(“#{}”)两种方式
配置文件如下:

第一种方式@Value(“${属性名}”):

第二种方式@value("#{}")
说一下${}和#{}区别.
@Value的值有两类:
① ${ property : default_value }
② #{ obj.property? :default_value }
第一个注入的是外部配置文件对应的property,第二个则是SpEL表达式对应的内容。 那个
default_value,就是前面的值为空时的默认值。注意二者的不同,#{}里面那个obj代表对象。
好了,知道了#{}的用法 我们改进一下,如图 准备一个实体类,并且注册到sping中:


网友评论