Home  >  Article  >  Backend Development  >  javascript - About the use of EL expressions

javascript - About the use of EL expressions

PHP中文网
PHP中文网Original
2016-08-04 09:20:561008browse

When I was coding today, I found two ways to use el expressions. I don’t know if they can be used in this way, but there was no error and the value could be obtained correctly.

First type:

javascript - About the use of EL expressions

Second type:

javascript - About the use of EL expressions

This is a closer look at the last subtotal (only this one has been changed). You can get the value in this way. What is the difference between the two? ? (The orderItem attribute is private)

Reply content:

javascript - About the use of EL expressions

I believe that when you read the document (note that I selected the part), you will know that directly accessing the attribute does not mean that the EL expression has permission to access a JavaBean Private properties, but data obtained by automatically calling the getProperty method.

In your question, since ${orderItem.getSubtotal()} is available, it means that you really provide a getter method, so you can naturally get the data directly using the attribute name.

To be precise, obtaining through the attribute name is just a shorthand syntax sugar for obtaining data through the getter method.

In fact, the specific implementation of the first writing method is also to call the getSubtotal() method. There is no difference between the two. The difference

*.abc
*.getAbc()

is not any difference, .abc still becomes .getAbc()
after processing. This leads to the conclusion that anything with a getter method can use attributes to get the value


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn