Spring Tutorial – Spring Expression Language (EL)

Spring Expression Language

Spring Tutorial – Spring Expression Language (EL)

Baxış:

Bahar İfadə Dili,,en,SpEL kimi qısaldılmışdır,,en,əsasən ifadə dilidir,,en,İşlərində çox güclüdür və sorğu və iş zamanı bir obyekt qrafiki ilə manipulyasiya üçün dəstək təklif edir,,en,Xüsusiyyət Bahar ilə sərbəst buraxıldı,,en,Dilin sintaksisi Unified EL ilə olduqca oxşar olsa da,,en,daha çox xüsusiyyət təklif edir,,en,Onlardan,,en,ən populyar olanlar simli şablonlar və metod çağırışıdır,,en,Bir neçə var,,en,ifadə dilləri mövcuddur,,en,bunlar JBoss EL,,en,MVEL,,en,ONGL və daha çox,,en,ayrıca Bahar İfadə Dilinin yaradılması, Bahar icmasının hər şeydə istifadə edilə bilən tək bir dəstək ifadə ifadəsinə sahib olmasını təmin etmək idi.,,en,Xüsusiyyətlərinin çoxu, əsasən Bahar mühitində layihələrin olma ehtimalı ilə bağlıdır,,en, abbreviated as SpEL, is basically an expression language. It is very powerful in its workings and offers support for queries and manipulation of an object graph during runtime. The feature was released with Spring 3.0 in 2009.

While the syntax of the language is pretty similar to Unified EL, it does offer more features. Of them, the most popular ones are string templates and method invocation. There are several Java expression languages available, them being JBoss EL, MVEL, ONGL and more. However, the creation of a separate Spring Expression Language was to ensure that the Spring community had a single supportive expression language that could be used across everything in the Spring framework. Many of its features are largely due to the requirements that projects are likely to have in the Spring environment, kimi kodun tamamlanması üçün alətlər,,en,Tool Suite,,en,SpEL agnostik API-yə əsaslanır,,en,Bunu etmək lazım olduqda digər ifadə dilləri inteqrasiya edilə bilər,,en,Baharın olmasına baxmayaraq ifadə qiymətləndirmənin işlədiyi təməl çərçivəsidir,,en,bundan asılı deyil,,en,Müstəqildir və müstəqil ifadə dili kimi nəzərdən keçirilə bilər,,en,Niyə SpEL,,en,Nəzərə alsaq ki, ifadələrin qiymətləndirilməsi üçün istifadə edilə bilən bir neçə dil var,,en,Baharın bir neçə səbəbi ilə seçilir,,en,Bahar İfadə Dilini niyə düşünməyinizə dair bir neçə səbəb var,,en,Sintaksis,,en,SpEL hər iki izahat metadatasında istifadə edilə bilər,,en,Yaz konfiqurasiyası,,en,və XML,,en,Hər iki halda da,,en,təyin sintaksis istifadə edərək yer tutur,,en,“SpEL-də ifadə sətri”,,en,iş vaxtının qiymətləndirilməsi üçün,,en,Kodu azaldır,,en yaz Tool Suite. SpEL is based on agnostic API, meaning other expression languages can be integrated when it is necessary to do so. Despite Spring being the foundation framework on which expression evaluation works, it is not dependent on it. It is independent and can be viewed as an independent expression language.

Must Read – Learn Spring AOP in 30 minutes








Why SpEL?

Considering that there are several languages that can be used for the evaluation of expressions, Spring does stand out for a few reasons. Here are a few reasons as to why you should consider Spring Expression Language.

  • Syntax

SpEL can be used in both annotation metadata (Spring configuration) and XML. In both the cases, the designation takes place using the syntax #{“expression string in SpEL”} for runtime evaluation.

  • Reduces code

SpEL, orada olan bir çox ifadə dillərinə çox sadə bir alternativdir,,en,sizin üçün bir çox kodu azalda bilər,,en,SpEL istifadə edərkən,,en,kodlaşdırıcının ifadələrin yalnız müəyyən xüsusiyyətlər sənədində yazılmasına diqqət yetirməsi lazımdır,,en,Çərçivə kodu yeni məlumatların çıxarılması işlənməsindən məsuldur,,en,Bahar İfadə Dili aşağıda bəhs olunan bir sıra xüsusiyyətlərlə gəlir -,,en,Daimi ifadələr,,en,Hərfi ifadələr,,en,Sinif ifadələri,,en,Mantiq və əlaqəli operatorlar,,en,Təyinat operatorları,,en,Şablon ifadələr,,en,Metod çağırışı,,en,Konstruktorları axtarırıq,,en,Kolleksiya seçimi və proyeksiyası,,en,Dəyişənlər,,en,Üçlü operator,,en,Dizinin qurulması,,en,İstifadəçi tərəfindən müəyyən edilmiş funksiyalar,,en,İnline siyahılar,,en,Lobya istinadları,,en,Dizilərə giriş,,en,siyahılar,,en,xəritələr,,en,Bəzi xüsusiyyətlər aşağıdakı nümunələrdə veriləcəkdir,,en. In fact, it can reduce a lot of code for you.

  • sadələşdirilmiş

When using SpEL, the coder only needs to take care of writing the expressions in certain properties file. The framework code is responsible for extraction handling of the new data.

What are the features?

Spring Expression Language comes with a number of features which have been mentioned below –

  • Regular expressions
  • Literal expressions
  • Class expressions
  • Boolean and relational operators
  • Assignment operators
  • Templated expressions
  • Method invocation
  • Calling constructors
  • Collection selection and projection
  • Variables
  • Ternary operator
  • Array construction
  • User defined functions
  • Inline lists
  • Bean references
  • Accessing arrays, lists, properties, maps

Some of the features will be covered in the following examples. Digər xüsusiyyətlər də nümunə tətbiqetmələrdən istifadə etməklə test edilə bilər,,en,Ancaq tətbiq quruluşu əvvəlki kimi qalacaq,,en,İndi mühitiniz Bahar əsaslı Java tətbiqetmələrinin inkişafına başlamağa hazırdır,,en,Bu bölmədə bir XML sənədində istifadə olunan ifadə dilini araşdıracağıq,,en,İfadə dili Java sənədində əlavə olaraq istifadə edilə bilər,,en,EL izahat kimi istifadə olunursa,,en,sonra XML faylı tələb olunmur,,en,EL ümumiyyətlə kimi yazılır,,en,SPEL ifadəsi,,sv,Aşağıda Product lobya istinadına sahib olan sadə bir şirkət lobya verilmişdir,,en,Aşağıda göstərildiyi kimi məhsulun adını və qiymətini ehtiva edir,,en,Şirkət lobya,,en,com.techalpine.spel,,sv,Məhsul məhsulu,,en,Simli ad,,en,Simli qiymət,,en,String getPrprice,,en,qiymət,,ro,setPrprice,,en,prprice = prprice,,ro,Məhsul getProduct,,en,setProduct,,en,məhsul = məhsul,,en,String getPrname,,en,ad,,en,setPrname,,en,ad = prname,,en. But the application structure will remain the same.

Must Read – Bahar inteqrasiyası ilə işləmək üçün addımlar,en

Environment setup:

Setting up the environment for Spring based application development involves just three major steps.

  • Setting up Java Development Kit

Download JDK from the Oracle site and then, install and configure it. Then the PATH and JAVA_HOME environment variables must be set.

  • Setting of Eclipse IDE

Eclipse can be downloaded from the rəsmi internet səhifəsi. Once downloaded, unpack the binaries and then set the PATH as well.

  • Setting up Spring libraries

The Spring libraries may be obtained from http://repo.spring.io/release/org/springframework/spring/. Again, it is important to set the CLASSPATH correctly.

Now your environment is ready to start developing Spring based Java applications.








Nümunə proqram:

In this section we will explore expression language used in an XML file. The expression language can also be used as annotation in Java file. If the EL is used as annotation, then XML file is not required. EL is generally written as #{SpEL expression}

Following is a simple company bean having reference of Product bean. It contains product name and price as shown below.

Listing 1: Company bean

package com.techalpine.spel;

ictimai sinif Şirkət {

xüsusi Product product;

xüsusi String prname;

xüsusi String prprice;

ictimai String getPrprice() {

return prprice;

}

ictimai ləğv setPrprice(String prprice) {

bu.prprice = prprice;

}

ictimai Product getProduct() {

return product;

}

ictimai ləğv setProduct(Product product) {

bu.product = product;

}

ictimai String getPrname() {

return prname;

}

ictimai ləğv setPrname(String prname) {

bu.prname = prname;

}

}

Aşağıda adı və qiyməti olan məhsul lobya verilir,,en,Yuxarıda şirkət lobya istinad edilir,,en,Məhsul paxlası,,en,Məhsul,,en,Simli qiymət,,en,String getPrice,,en,qiymət,,en,setPrice,,nl,qiymət = qiymət,,en,bu XML sənədidir,,en,Budur məhsul paxlası,,en,məhsul adı və məhsul qiyməti ifadə dili olaraq qeyd olunur,,en,Varsayılan dəyərlər XML sənədində də müəyyən edilir,,en,Belə ki, bunlar şirkət lobya da mövcud olacaq,,en,Xahiş edirəm fasilə faylında ifadə dili sintaksisinin necə istifadə olunduğunu yoxlayın,,en,Bənzər sintaksis, annotasiya əsaslı proqram halında da istifadə olunur,,en,Konfiqurasiya XML,,en,prodBean,,en,oyun.Məhsul,,nl,Şirkət Bean,,ro,şirkət,,en,prodBean.name,,en,prodBean.price,,en,Bu əsas Java tətbiqetməsidir,,en,Şirkət lobya istinadını alır və sonra məhsulun adını və qiymətini yazdırır,,en. It is referred in company bean above.

Listing 2: Product bean

package com.techalpine.spel;

ictimai sinif Product {

xüsusi String adı;

xüsusi String price;

ictimai String getName() {

return ad;

}

ictimai ləğv setName(String adı) {

bu.name = adı;

}

ictimai String getPrice() {

return price;

}

ictimai ləğv setPrice(String price) {

bu.price = price;

}

}

Now, this is the XML file. Here product bean, product name and product price is mentioned as expression language. The default values are also set in the XML file. So these will be available in the company bean also. Please check how the expression language syntax is used in the bean file. Similar syntax is also used in case of annotation based program.

Listing 3: Configuration XML

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”>

<bean id=“prodBean” class=“com.techalpine.spel.Product”>

<property name=“ad” value=“Car” />

<property name=“price” value=“1000000” />

</bean>

<bean id=“companyBean” class=“com.techalpine.spel.Company”>

<property name=“product” value=“#{prodBean}” />

<property name=“prname” value=“#{prodBean.name}” />

<property name=“prprice” value=“#{prodBean.price}” />

</bean>

</beans>

This is the main Java application. It gets reference of the company bean and then prints the product name and price. Bəzi xüsusiyyətlər və onların dəyərləri də oxşar şəkildə enjekte edilə və nümunə tətbiqində istifadə edilə bilər,,en,Test etmək üçün əsas Java proqramı,,en,GameMain,,nl,WebContent / WEB-INF / spelConfig.xml,,nl,Tətbiqi işə saldıqdan sonra konsolda aşağıdakı çıxış göstərilir,,en,Birləşdirilmiş EL-ə bənzər bir ifadə dilləri axtarırsınızsa, Bahar İfadə Dili əla bir seçim ola bilər,,en,SpEL, iş vaxtında dinamik olaraq dəyərlər təyin etməyə imkan verir və buna görə də proqramçı tərəfindən çoxlu kodlaşdırmaya qənaət edir,,en,iki fərqli konfiqurasiya sxemində də işləyə bilər - XML ​​və şərh əsaslı,,en,hər hansı bir seçim ehtiyacınıza uyğun olaraq seçilə bilər,,en,Spring EL çox güclüdür və tətbiqinizə daha çox funksionallıq əlavə etmək üçün genişləndirilə bilər,,en,Baharla əlaqəli məqalələr,,en.

Listing 4: Main Java program to test

package com.techalpine.spel;

idxal org.springframework.context.ApplicationContext;

idxal org.springframework.context.support.FileSystemXmlApplicationContext;

ictimai sinif SpELMain {

ictimai statik ləğv əsas(Sim[] args) {

ApplicationContext context = yeni FileSystemXmlApplicationContext(

“WebContent/WEB-INF/spelConfig.xml”);

Company compobj = (Şirkət) context.getBean(“companyBean”);

Sistem.həyata.println(“Product Name: “+compobj.getPrname());

Sistem.həyata.println(“Product Price: “+compobj.getPrprice());

}

}

Once you run the application following output will be display on the console.

Product Name: Car

Product Price: 1000000

Must Read – Learn Spring Boot in 30 Minutes








Nəticə:

Spring Expression Language can be a great option if you are looking for an expression languages that is similar to the Unified EL. SpEL allows you to dynamically assign values at runtime and therefore saves a lot coding on the part of the programmer. Besides, it can also work on two different configuration schemes – XML and annotation based. So, any option can be selected as per your need. Spring EL is very powerful and it can be extended to add more functionality in your application.

Explore – Spring related articles

 

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share