1 packagecom.ieou.capsule_basic_info.util; 2 3 4 importorg.springframework.beans.factory.annotation.Value; 5 importorg.springframework.stereotype.Component; 6 importorg.springframework.web.bind.annotation.RequestMapping; 7 importorg.springframework.web.bind.annotation.RestController; 8 9 @RestController 10 @RequestMapping("/login") 11 @Component 12 public classTestController { 13 14 /************************ @Value("#{}") *********************************/ 15 16 //这是 @Value("#{}") 17 18 @Value("#{1}") 19 private int number; //获取数字 1 20 21 @Value("#{'Spring Expression Language'}") //获取字符串常量 22 privateString str; 23 24 25 @Value("#{dataSource.jdbcUrl}") //获取bean的属性 26 privateString jdbcUrl; 27 28 /************************** @Value("${}") ***********************************/ 29 30 //@Value("${}") 有两种用法 31 //1.从properties配置文件中读取数据 32 @Value("${test_value}") //获取字符串常量 33 private String str1; //str1 = hello world 34 35 //2.为方法参数赋值 36 @Value("${test_value}") 37 public voidtest(String s){ 38 System.out.println(s); //s = hello world 39 } 40 41 42 }
@Value("#{}")与@Value("${}")的区别以及用法
免责声明:文章转载自《@Value("#{}")与@Value("${}")的区别以及用法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇根据wsdl反向生成webservice服务端(3种方法)JAVA线程池调优下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=