zoukankan      html  css  js  c++  java
  • @Value("#{}")与@Value("${}")的区别以及用法

     1 package com.ieou.capsule_basic_info.util;
     2 
     3 
     4 import org.springframework.beans.factory.annotation.Value;
     5 import org.springframework.stereotype.Component;
     6 import org.springframework.web.bind.annotation.RequestMapping;
     7 import org.springframework.web.bind.annotation.RestController;
     8 
     9 @RestController
    10 @RequestMapping("/login")
    11 @Component
    12 public class TestController {
    13 
    14     /************************   @Value("#{}")   *********************************/
    15 
    16     //这是  @Value("#{}")
    17 
    18     @Value("#{1}")
    19     private int number; //获取数字 1
    20 
    21     @Value("#{'Spring Expression Language'}") //获取字符串常量
    22     private String str;
    23 
    24 
    25     @Value("#{dataSource.jdbcUrl}") //获取bean的属性
    26     private String 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 void test(String s){
    38         System.out.println(s);  // s = hello world
    39     }
    40     
    41     
    42 } 

    @Value("#{}")   SpEL表达式
    @Value("#{}") 表示SpEl表达式通常用来获取bean的属性,或者调用bean的某个方法。当然还有可以表示常量

  • 相关阅读:
    自定义类似MessageBox小窗体操作
    WinForm 遍历用户控件里CheckBox
    WinForm BaseClass类常用通用方法
    分页的几种写法
    克服粗心毛病的伪代码
    C++queue的使用
    Unix网络编程学习 < 一 >
    使用log4cxx
    memset函数
    libcurl在windows下的使用
  • 原文地址:https://www.cnblogs.com/wang-yaz/p/10567716.html
Copyright © 2011-2022 走看看