首页 > 其他 > 详细

@Value注解

时间:2019-10-24 12:45:11      阅读:63      评论:0      收藏:0      [点我收藏+]

1.注入 基本字符 

public class Student {
@Value("qq")
private String name;
@Value("12")
private Integer age;

2.el表达式 

public class Student {
@Value("qq")
private String name;
@Value("#{20-2}")
private Integer age;

3.读取配置文件 

配置文件 

student.name=Martin

  配置类  

@Configuration
@PropertySource(value = "classpath:/app.properties")
public class Config {

    @Bean
    public Student student(){
        return new Student();
    }

}

  Bean类 

public class Student{
    @Value("${student.name}")
    private String name;

    private Integer age;

 

 

      

@Value注解

原文:https://www.cnblogs.com/qin1993/p/11731377.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!