View all fields / properties of bean in JSP / JSTL

后端 未结 4 1503
误落风尘
误落风尘 2020-12-23 09:53

I have a bean, ${product}. I would like to view all of the available fields / properties of this bean. So for instance, ${product.price}, ${p

4条回答
  •  暖寄归人
    2020-12-23 10:44

    What you want to do is basically void of sense, as it is you who must know beforehand what the object is and what are its fields. If for some reason you still want to proceed, you can have a method that returns what you want:

    public Map getProperties() {
        //create your map and populate it via plain strings-getters for fields
        //or use Java Reflection API
    }
    

    With this method your map will be accessible with

    ${bean.properties}
    

提交回复
热议问题