In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Spring EL". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Spring EL.
One: description
Spring EL-Spring expression language, which supports the use of expressions in xml and annotations, similar to JSP's EL expression language.
Spring development often involves the call of various resources, including ordinary files, web addresses, configuration files, system environment variables and so on. We can use Spring's expression language to inject resources.
Two: code examples
@ Service
Public class DemoService {
@ Value (Properties of other classes)
Private String another
/ * *
* @ return the another
, /
Public String getAnother () {
Return another
}
/ * *
* @ param another
* the another to set
, /
Public void setAnother (String another) {
This.another = another
}
}
Click (here) to collapse or open
@ Configuration
@ ComponentScan ("com.gemdale")
@ PropertySource ("classpath:com/gemdale/gmap/spring/boot/demo/el/test.properties")
Public class ElConfig {
@ Value ("I love youe!")
Private String normal
@ Value ("# {systemProperties ['os.name']}")
Private String osName
@ Value ("# {T (java.lang.Math) .random () * 100.0}")
Private double randomNumber
@ Value ("# {demoService.another}")
Private String fromAnother
@ Value ("classpath:com/gemdale/gmap/spring/boot/demo/el/test.txt")
Private Resource testFile
@ Value ("http://www.baidu.com")"
Private Resource testUrl
@ Value ("${book.name}")
Private String bookName
@ Autowired
Private Environment environment
@ Bean
Public static PropertySourcesPlaceholderConfigurer propertyConfigure () {
Return new PropertySourcesPlaceholderConfigurer ()
}
Public void outputResource () {
Try {
System.out.println (normal)
System.out.println (osName)
System.out.println (randomNumber)
System.out.println (fromAnother)
System.out.println (IOUtils.toString (testFile.getInputStream ()
System.out.println (IOUtils.toString (testUrl.getInputStream ()
System.out.println (bookName)
System.out.println (environment.getProperty ("book.author"))
}
Catch (Exception e) {
E.printStackTrace ()
}
}
}
Click (here) to collapse or open
Public class Start {
Public static void main (String [] args) throws Exception {
AnnotationConfigApplicationContext configApplicationContext = new AnnotationConfigApplicationContext (
ElConfig.class)
ElConfig resourceService = configApplicationContext.getBean (ElConfig.class)
ResourceService.outputResource ()
ConfigApplicationContext.close ()
}
}
Book.author=GH
Book.name=spring boot
Thank you for your reading, the above is the content of "how to use Spring EL", after the study of this article, I believe you have a deeper understanding of how to use Spring EL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.