Use Dynabean to reduce unnecessary VO and FORMBEAN

xiaoxiao2021-03-06  38

Dynabean is one of the treasures in Beanutils. With a dynamic bean, you don't have to write so many VOs, especially those that are just to interact with View, i Hate Form Bean.

Dynabean usage is simple, especially after lazybynabean.

Dynabean car = new lazydynabean (); car.set ("carno", 1); car.set ("Owner", "Zhang 3");

Out.print (car.get ("carno"));

Look at a function like a MAP, but more reflection, so supports those who use reflection to obtain attributes.

But because he doesn't have a function such as Car.Getcarno (), you can only use car.get ("carno"), so you don't support the in JSTL. Because JSTL is converted back to car.getcarno by default. And several discussions, JSTL does not support car.userFunction (), the reason is that there is no need to have Java code in the code: (So, or write <% = car.get ("carno")> Ok, if it is a JSTL In the loop structure, it is necessary to take the bean from pagecontext, or write TAG, fortunately, it is very simple, using the beanutils.getproperty function, or, use Velocity and FreeMarker.

Finally, if car.set ("carno", null) gets an inexplicable object object, if you want it to null, you need to define his type first. Therefore, for columns that may be null, you need to define type with lazyclass, but fortunately, it is also very lazy, it is impossible to be NULL values.

Lazydynaclass lc = new lazydynaclass (); lc.add ("owner", string.class); // Specify NULL Converter String Dynabean Car = New Lazy Dynabean (LC); Car.Set ("Carno", 1); Car.set ("Owner", NULL;

转载请注明原文地址:https://www.9cbs.com/read-61275.html

New Post(0)