Avoid complicated GETSET operations

xiaoxiao2021-03-06  20

Avoiding the complicated GET / SET operation is taken from: Xia Zhen hibernate_dev_guide To avoid the complicated Get / set operation, you can batch copy functionality provided by the Apache Jakarta Commons Beanutils component (http://jakarta.apache.org/commons/beanutils/ ). In the following example, we copy all properties of the User object to the AnotherUser object:

Tuser = new tuser ();

Tuser anotheruser = new tuser ();

User.setname ("EMMA");

User.setUsertype (1);

Try {

Beanutils.copyProperties (Anotheruser, User);

System.out.println ("UserName =>"

anotheruser.getname ()

);

System.out.println ("UserType =>"

AnotherUser.getusertype ()

);

} catch (IllegaCcessException E) {

E.PrintStackTrace ();

} catch (invocationTargeTexception E) {

E.PrintStackTrace ();

}

Tuser = new tuser ();

Tuser anotheruser = new tuser ();

User.setname ("EMMA");

User.setUsertype (1);

Try {

Beanutils.copyProperties (Anotheruser, User);

System.out.println ("UserName =>"

anotheruser.getname ()

);

System.out.println ("UserType =>"

AnotherUser.getusertype ()

);

} catch (IllegaCcessException E) {

E.PrintStackTrace ();

} catch (invocationTargeTexception E) {

E.PrintStackTrace ();

}

Tuser = new tuser ();

Tuser anotheruser = new tuser ();

User.setname ("EMMA");

User.setUsertype (1);

Try {

Beanutils.copyProperties (Anotheruser, User);

System.out.println ("UserName =>"

anotheruser.getname ()

);

System.out.println ("UserType =>"

AnotherUser.getusertype ()

);

} catch (IllegaCcessException E) {

E.PrintStackTrace ();

} catch (invocationTargeTexception E) {

E.PrintStackTrace ();

}

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

New Post(0)