Techniques of EL on Java

2019-08-08 22:19发布

问题:

I interest in creating my own service for some EL language for POJO. For example, I have some object structure with inner POJO objects, A and B for example. So, I want pass to my service string like "a.b.name" and than get this property value.

Are there any utils in java reflection api or 3rd part libraries?

I can parse this string by myself and then get fields and methods, but I think this is common feature. Any ideas?

回答1:

Maybe you should look at the Spring Expression language or Groovy.

Spring EL is a full featured expression language (you should be able to use it without using the rest of the framework).

Groovy is a JVM language that can be easily integrated into java applications and it powerfull syntax can be very useful for such tasks. Since its compatible to Java you can access and modify your Java objects from groovy code.

You can also look at Jexl. I haven't used this one so far but it looks useful for your task.



回答2:

Here are some more options that are available:

  • OGNL
  • MVEL
  • Velocity


回答3:

I used MVEL

It really reduced the code.