具有相同屬性名稱的物件之間的屬性值複製,具體**如下
public
class
beanutil
/*** 複製物件屬性
**@param from
*@param to
*@param excludsarray
* 排除屬性列表
*@throws exception
*/public
static
void
copypropertie***clude(object from, object to,
string excludsarray) throws exception
method frommethods = from.getclass().getdeclaredmethods();
method tomethods = to.getclass().getdeclaredmethods();
method frommethod = null, tomethod = null;
string frommethodname = null, tomethodname = null;
for (int i = 0; i < frommethods.length; i++)
tomethodname = "set" + frommethodname.substring(3);
tomethod = findmethodbyname(tomethods, tomethodname);
if (tomethod == null)
continue;
object value = frommethod.invoke(from, new object[0]);
if (value == null)
continue;
// 集合類判空處理
if (value instanceof collection)
tomethod.invoke(to, new object );}}
/*** 物件屬性值複製,僅複製指定名稱的屬性值
**@param from
*@param to
*@param includsarray
*@throws exception
*/public
static
void
copypropertiesinclude(object from, object to,
string includsarray) throws exception else
method frommethods = from.getclass().getdeclaredmethods();
method tomethods = to.getclass().getdeclaredmethods();
method frommethod = null, tomethod = null;
string frommethodname = null, tomethodname = null;
for (int i = 0; i < frommethods.length; i++)
tomethodname = "set" + frommethodname.substring(3);
tomethod = findmethodbyname(tomethods, tomethodname);
if (tomethod == null)
continue;
object value = frommethod.invoke(from, new object[0]);
if (value == null)
continue;
// 集合類判空處理
if (value instanceof collection)
tomethod.invoke(to, new object );}}
/*** 從方法陣列中獲取指定名稱的方法
**@param methods
*@param name
*@return
*/public
static method findmethodbyname(method methods, string name)
}return
null;
}}
java複製檔案工具類
public int copy string source name,string dest name,int type throws ioexception if source filefile.canread if dest filefile.exists else else else if p...
類 物件 屬性 方法
一程式一世界 1.類是抽象的,概念性的,代表的是一類事物 2.物件是具體的,實際的,代表乙個具體事物 3.類是物件的模板,物件是類的乙個個體,乙個例項。類由成員屬性和成員方法構成。注意 類名首字母要大寫,方法名首字母要小寫。成員方法命名 駝峰法 匈牙利法 比如myname 下劃線法,比如my nam...
動態陣列類 物件的淺複製 物件深複製
1.將動態陣列封裝成類 include include using namespace std class point point int x,int y x x y y point int getx const int gety const void move int newx,int newy ...