(Entity Bean) Dynamic Assignment Value Object - Dynamic CREATE VALUE Object Mode

zhaozj2021-02-11  201

From Entity Baen to Value Object Dynamic Create Your ValueObject: Use Value Object

Summary: In J2EE applications, JSP Bean Servlet EJB development is used. If your business interface has a large number of setter / getter methods, you need to repeat a large number of assignment statements, which describes how to dynamically assign value objects.

Why do you dynamically assign weak type values? J2EE can be developed, you may need to assign a large number of data from the client to your bean, transfer it to EJB, to reduce the network overhead, and repeat a lot of assignment statements every time, is it very Urgent, use a suitable strategy to eliminate this repetitive work and is a way to improve your productivity. How to dynamically assign weak type values ​​objects. Solving this problem You need to determine using the specified named mode. Bean property setName (), getName (), EJB also matches naming. You can use it to inherit the same interface to implement. Once you have specified naming mode, you can use simple code to implement dynamic.

The code is described as follows:

Public interface author {public string getName (); public void setname; ....}

Entity Bean Local Interface Extended Service Interface Public Interface Authorlocal Extends Author, EjblocalObject {}

Entity bean itself also interface extension business interface public abstract articlelocalbean imports author, entitybean {

...}

The user uses the sessionBean to get and update the value object. Public author getauthor () {Try {Return New Authorvalues ​​(Authorlocal);} catch (Exception E) {throw new EJBEXCEPTION ("Unable to create value object. Cause:" E.getMessage ());}}

Authorvalues ​​implements the Author interface, implements data assignment in the constructor

Public class authorvalues ​​implements author {

....

Public authorvalues ​​(author author) THROWS Exception {class c = this.getClass (); string methodname = null; object [] parameter = new object [1]; class [] returntype = new class [1];

Method [] methods = author.class.getMethods (); for (int i = 0; i

Public string getname () {return this.name;} public void setname {this.name = name;}

...}

As you can see, achieving dynamic assignment is very simple. I will tell the Lord bond in the next article.

Mode

Welcome everyone to discuss.

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

New Post(0)