This is the nature of expression language evaluation. when you use expression language it will search .(dot) in it if .(dot) found it will call getter of that properties other wise call toString() of that object
jquery parse spring mvc object auto call toString
-
05-07-2023 - |
题
I'm using JSP + MVC in web application. And I found that when jQuery parse a java object, it auto call Java's toString() method. Does there's any documentation to explain why?
example, JSP use department back from controller
${departmentList }
i can see toString() log in console.
but if i use
${departmentList.name }
it will only goto
getName() //(getter method).
解决方案
其他提示
What you are describing has nothing to do with jQuery.
${departmentList }
in your jsp is processed on the server side, not the client side.
What the engine that processes jsp does in this case is perfectly logical, it calls toString
just like System.out.println() would if you passed it departmentList
When however you use
${departmentList.name }
the engine that processes the jsp page will automatically can the getName
method on the object
不隶属于 StackOverflow