Home > Article > Backend Development > javascript - About the use of EL expressions
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.
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)
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