|
| |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
避免繁复的get/set操作 摘自:夏昕 Hibernate_DEV_GUIDE 为避免繁复的get/set操作,你可以通过Apache Jakarta Commons Beanutils 组件提供的属性批量复制功能(http://jakarta.apache.org/commons/beanutils/).下面的例子中,我们把user对象的所有属性复制到anotherUser对象中: TUser user = 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 (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } TUser user = 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 (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } TUser user = 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 (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } 返回类别: 教程 上一教程: Java多线程编程详解 下一教程: Java NIO API详解 您可以阅读与"避免繁复的get/set操作"相关的教程: · 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 · 关于如何使用JdbcTemplate实现在WebLogic812,Oracle9i上的CLOB数据的写操作 · Java的文件操作--2(Zip文件释放) · 对文件的操作 · JSP文件操作之追加篇 |
| 快精灵印艺坊 版权所有 |
首页 |
||