反射将一个对象所有字段的值赋给另一个相似的对象(进阶版1)
上个版本只能匹配两个相同字段的对象,这次我进行优化了一下,可以自己根据两个对象的名字来自由配置,不过对于字段类型的匹配还在研究中,一个一个类型去匹配的话感觉上去太麻烦了,也是想像字段名一样写一个properties来配置,暂时就只想到这么多,先把代码贴出来吧= =!
还有就是效率问题,上篇有个博友提出来的,不知道那个博友怎么做的,但我这个方法我测了一下,用时还是挺短的。。。
代码量略多。。。上一篇没有贴完整,这篇基本就是完整的了。
/* * 文 件 名: TestLast.java * 版 权: Copyright YYYY-YYYY, All rights reserved * 描 述: <描述> * 创 建 人: james * 创建时间: 2016年4月12日 */ package test; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Properties; /** * <一句话功能简述> * * @author james * @version [V1.00, 2016年4月12日] * @see [相关类/方法] * @since V1.00 */ public class TestFinal2 { private static String value; private static Properties prop = new Properties(); static { InputStream in; try { in = new BufferedInputStream(new FileInputStream("src/test/test.properties")); prop.load(in); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) throws InstantiationException, InvocationTargetException { long lasting = System.currentTimeMillis();// 效率检测 List<MtUserInfoRule> list = new ArrayList<MtUserInfoRule>(); for (int i = 0; i < 500; i++) { //int i = 1; MtUserInfoRule mt = new MtUserInfoRule(); mt.setName(i + ""); mt.setPassport(i + ""); mt.setAddress(i + ""); mt.setCredentials(i + ""); mt.setEmail(i + ""); mt.setHkmlp(i + ""); mt.setId(i + ""); mt.setMobile(i + ""); mt.setMtp(i + ""); mt.setTlp(i + ""); mt.setPinyin(i + ""); mt.setName2(i + ""); mt.setPassport2(i + ""); mt.setAddress2(i + ""); mt.setCredentials2(i + ""); mt.setEmail2(i + ""); mt.setHkmlp2(i + ""); mt.setId2(i + ""); mt.setMobile2(i + ""); mt.setMtp2(i + ""); mt.setTlp2(i + ""); mt.setPinyin2(i + ""); mt.setName3(i + ""); mt.setPassport3(i + ""); mt.setAddress3(i + ""); mt.setCredentials3(i + ""); mt.setEmail3(i + ""); mt.setHkmlp3(i + ""); mt.setId3(i + ""); mt.setMobile3(i + ""); mt.setMtp3(i + ""); mt.setTlp3(i + ""); mt.setPinyin3(i + ""); Person p = new Person(); p.setId_p(1); p.setName_p("personName"); p.setMen_p(true); p.setCh_p('a'); p.setFloat_p(1f); p.setDouble_p(2.0); p.setLong_p(2l); p.setShort_p((short) 3); p.setByte_p((byte) 4); Student s = new Student(); s.setId_s(11); s.setName_s("stuName"); p.setStudent_p(s); mt.setPerson(p); list.add(mt); } UserInfoRule info = new UserInfoRule(); for (MtUserInfoRule mt : list) { doField(mt, info); } long lasting2 = System.currentTimeMillis(); System.out.println("MtUserInfoRule--》UserInfoRule转换完成,用时" + (lasting2 - lasting) + "ms"); } private static void doField(Object obj, Object obj2) throws InstantiationException, InvocationTargetException { try { Field[] field1 = obj.getClass().getDeclaredFields(); Field[] field2 = obj2.getClass().getDeclaredFields(); for (Field p2 : field2) { boolean accessible = p2.isAccessible(); p2.setAccessible(true); String fieldName2 = p2.getName(); for (Field p1 : field1) { p1.setAccessible(true); String fieldName1 = p1.getName(); // 两个对象名字相同(如果两个对象名字有差异,则可以转换进行匹配) if (isMatch(fieldName1, fieldName2)) { //if (fieldName1.equals(fieldName2)) { // boolean类型的isMen的get方法名就是isMen String strGet = p1.getType().equals(Boolean.class) || p1.getType().equals(boolean.class) ? fieldName1 : ("get" + fieldName1.substring(0, 1).toUpperCase() + fieldName1.substring(1, fieldName1.length())); Method methodGet = obj.getClass().getDeclaredMethod(strGet); Object object1 = methodGet.invoke(obj); if (returnBoolean(p2)) { //System.out.println("======================"+p2.getType().newInstance()+" start ======================"); doField(object1, p2.getType().newInstance()); //System.out.println("======================"+p2.getType().newInstance()+" end ======================"); } else { if (boolean.class.equals(p2.getType()) || Boolean.class.equals(p2.getType())) { p2.set(obj2, "1".equals(object1) ? true : false); } else { p2.set(obj2, object1); } //System.out.println(p2.getName() + ":" + p2.get(obj2)); } break; } p1.setAccessible(accessible); } } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } /** * // marketPrice market_price <功能详细描述> * * @param name * @param name2 * @return * @see [类、类#方法、类#成员] */ private static boolean isMatch(String name1, String name2) { value = prop.getProperty(name2); if (name1.equals(value)) { return true; } return false; } // 判断是否是基本数据类型或者是String、Date(可能不全面,可能还有其他类型) public static boolean returnBoolean(Field f) { Class t = f.getType(); if (String.class.equals(t) || Date.class.equals(t) || byte.class.equals(t) || Byte.class.equals(t) || short.class.equals(t) || Short.class.equals(t) || float.class.equals(t) || Float.class.equals(t) || long.class.equals(t) || Long.class.equals(t) || int.class.equals(t) || Integer.class.equals(t) || double.class.equals(t) || Double.class.equals(t) || boolean.class.equals(t) || Boolean.class.equals(t) || char.class.equals(t) || Character.class.equals(t)) { return false; } return true; } }
/* * 文 件 名: MTUserInfoRule.java * 版 权: Copyright YYYY-YYYY, All rights reserved * 描 述: <描述> * 创 建 人: james * 创建时间: 2016年4月11日 */ package test; /** * <一句话功能简述> * * @author james * @version [V1.00, 2016年4月11日] * @see [相关类/方法] * @since V1.00 */ public class MtUserInfoRule { // columns START /** 变量 id . */ private String id; /** 变量 name . */ private String name; /** 变量 pinyin . */ private String pinyin; /** 变量 mobile . */ private String mobile; /** 变量 address . */ private String address; /** 变量 email . */ private String email; /** 变量 hkmlp . */ private String hkmlp; /** 变量 tlp . */ private String tlp; /** 变量 mtp . */ private String mtp; /** 变量 passport . */ private String passport; /** 变量 credentials . */ private String credentials; // columns END /** 变量 id . */ private String id2; /** 变量 name . */ private String name2; /** 变量 pinyin . */ private String pinyin2; /** 变量 mobile . */ private String mobile2; /** 变量 address . */ private String address2; /** 变量 email . */ private String email2; /** 变量 hkmlp . */ private String hkmlp2; /** 变量 tlp . */ private String tlp2; /** 变量 mtp . */ private String mtp2; /** 变量 passport . */ private String passport2; /** 变量 credentials . */ private String credentials2; /** 变量 id . */ private String id3; /** 变量 name . */ private String name3; /** 变量 pinyin . */ private String pinyin3; /** 变量 mobile . */ private String mobile3; /** 变量 address . */ private String address3; /** 变量 email . */ private String email3; /** 变量 hkmlp . */ private String hkmlp3; /** 变量 tlp . */ private String tlp3; /** 变量 mtp . */ private String mtp3; /** 变量 passport . */ private String passport3; /** 变量 credentials . */ private String credentials3; private Person person; /** * 获取 person * @return 返回 person */ public Person getPerson() { return person; } /** * 设置 person * @param 对person进行赋值 */ public void setPerson(Person person) { this.person = person; } /** * 获取 id2 * @return 返回 id2 */ public String getId2() { return id2; } /** * 设置 id2 * @param 对id2进行赋值 */ public void setId2(String id2) { this.id2 = id2; } /** * 获取 name2 * @return 返回 name2 */ public String getName2() { return name2; } /** * 设置 name2 * @param 对name2进行赋值 */ public void setName2(String name2) { this.name2 = name2; } /** * 获取 pinyin2 * @return 返回 pinyin2 */ public String getPinyin2() { return pinyin2; } /** * 设置 pinyin2 * @param 对pinyin2进行赋值 */ public void setPinyin2(String pinyin2) { this.pinyin2 = pinyin2; } /** * 获取 mobile2 * @return 返回 mobile2 */ public String getMobile2() { return mobile2; } /** * 设置 mobile2 * @param 对mobile2进行赋值 */ public void setMobile2(String mobile2) { this.mobile2 = mobile2; } /** * 获取 address2 * @return 返回 address2 */ public String getAddress2() { return address2; } /** * 设置 address2 * @param 对address2进行赋值 */ public void setAddress2(String address2) { this.address2 = address2; } /** * 获取 email2 * @return 返回 email2 */ public String getEmail2() { return email2; } /** * 设置 email2 * @param 对email2进行赋值 */ public void setEmail2(String email2) { this.email2 = email2; } /** * 获取 hkmlp2 * @return 返回 hkmlp2 */ public String getHkmlp2() { return hkmlp2; } /** * 设置 hkmlp2 * @param 对hkmlp2进行赋值 */ public void setHkmlp2(String hkmlp2) { this.hkmlp2 = hkmlp2; } /** * 获取 tlp2 * @return 返回 tlp2 */ public String getTlp2() { return tlp2; } /** * 设置 tlp2 * @param 对tlp2进行赋值 */ public void setTlp2(String tlp2) { this.tlp2 = tlp2; } /** * 获取 mtp2 * @return 返回 mtp2 */ public String getMtp2() { return mtp2; } /** * 设置 mtp2 * @param 对mtp2进行赋值 */ public void setMtp2(String mtp2) { this.mtp2 = mtp2; } /** * 获取 passport2 * @return 返回 passport2 */ public String getPassport2() { return passport2; } /** * 设置 passport2 * @param 对passport2进行赋值 */ public void setPassport2(String passport2) { this.passport2 = passport2; } /** * 获取 credentials2 * @return 返回 credentials2 */ public String getCredentials2() { return credentials2; } /** * 设置 credentials2 * @param 对credentials2进行赋值 */ public void setCredentials2(String credentials2) { this.credentials2 = credentials2; } /** * 获取 id3 * @return 返回 id3 */ public String getId3() { return id3; } /** * 设置 id3 * @param 对id3进行赋值 */ public void setId3(String id3) { this.id3 = id3; } /** * 获取 name3 * @return 返回 name3 */ public String getName3() { return name3; } /** * 设置 name3 * @param 对name3进行赋值 */ public void setName3(String name3) { this.name3 = name3; } /** * 获取 pinyin3 * @return 返回 pinyin3 */ public String getPinyin3() { return pinyin3; } /** * 设置 pinyin3 * @param 对pinyin3进行赋值 */ public void setPinyin3(String pinyin3) { this.pinyin3 = pinyin3; } /** * 获取 mobile3 * @return 返回 mobile3 */ public String getMobile3() { return mobile3; } /** * 设置 mobile3 * @param 对mobile3进行赋值 */ public void setMobile3(String mobile3) { this.mobile3 = mobile3; } /** * 获取 address3 * @return 返回 address3 */ public String getAddress3() { return address3; } /** * 设置 address3 * @param 对address3进行赋值 */ public void setAddress3(String address3) { this.address3 = address3; } /** * 获取 email3 * @return 返回 email3 */ public String getEmail3() { return email3; } /** * 设置 email3 * @param 对email3进行赋值 */ public void setEmail3(String email3) { this.email3 = email3; } /** * 获取 hkmlp3 * @return 返回 hkmlp3 */ public String getHkmlp3() { return hkmlp3; } /** * 设置 hkmlp3 * @param 对hkmlp3进行赋值 */ public void setHkmlp3(String hkmlp3) { this.hkmlp3 = hkmlp3; } /** * 获取 tlp3 * @return 返回 tlp3 */ public String getTlp3() { return tlp3; } /** * 设置 tlp3 * @param 对tlp3进行赋值 */ public void setTlp3(String tlp3) { this.tlp3 = tlp3; } /** * 获取 mtp3 * @return 返回 mtp3 */ public String getMtp3() { return mtp3; } /** * 设置 mtp3 * @param 对mtp3进行赋值 */ public void setMtp3(String mtp3) { this.mtp3 = mtp3; } /** * 获取 passport3 * @return 返回 passport3 */ public String getPassport3() { return passport3; } /** * 设置 passport3 * @param 对passport3进行赋值 */ public void setPassport3(String passport3) { this.passport3 = passport3; } /** * 获取 credentials3 * @return 返回 credentials3 */ public String getCredentials3() { return credentials3; } /** * 设置 credentials3 * @param 对credentials3进行赋值 */ public void setCredentials3(String credentials3) { this.credentials3 = credentials3; } /** * MtUserInfoRule 的构造函数 */ public MtUserInfoRule() { } /** * MtUserInfoRule 的构造函数 */ public MtUserInfoRule(String id) { this.id = id; } public void setId(String value) { this.id = value; } public String getId() { return this.id; } public String getPk() { return this.id; } public void setName(String value) { this.name = value; } public String getName() { return this.name; } public void setPinyin(String value) { this.pinyin = value; } public String getPinyin() { return this.pinyin; } public void setMobile(String value) { this.mobile = value; } public String getMobile() { return this.mobile; } public void setAddress(String value) { this.address = value; } public String getAddress() { return this.address; } public void setEmail(String value) { this.email = value; } public String getEmail() { return this.email; } public void setHkmlp(String value) { this.hkmlp = value; } public String getHkmlp() { return this.hkmlp; } public void setTlp(String value) { this.tlp = value; } public String getTlp() { return this.tlp; } public void setMtp(String value) { this.mtp = value; } public String getMtp() { return this.mtp; } public void setPassport(String value) { this.passport = value; } public String getPassport() { return this.passport; } public void setCredentials(String value) { this.credentials = value; } public String getCredentials() { return this.credentials; } }
/* * 文 件 名: UserInfoRule.java * 版 权: Copyright YYYY-YYYY, All rights reserved * 描 述: <描述> * 创 建 人: james * 创建时间: 2016年4月11日 */ package test; /** * <一句话功能简述> * * @author james * @version [V1.00, 2016年4月11日] * @see [相关类/方法] * @since V1.00 */ public class UserInfoRule{ private boolean _name; private boolean _pinyin; private boolean _mobile; private boolean _credentials; private boolean _address; private boolean _email; private boolean _hkmlp; private boolean _tlp; private boolean _mtp; private boolean _passport; private boolean _name2; private boolean _pinyin2; private boolean _mobile2; private boolean _credentials2; private boolean _address2; private boolean _email2; private boolean _hkmlp2; private boolean _tlp2; private boolean _mtp2; private boolean _passport2; private boolean _name3; private boolean _pinyin3; private boolean _mobile3; private boolean _credentials3; private boolean _address3; private boolean _email3; private boolean _hkmlp3; private boolean _tlp3; private boolean _mtp3; private boolean _passport3; private Person _person; /** * 获取 _name2 * @return 返回 _name2 */ public boolean is_name2() { return _name2; } /** * 设置 _name2 * @param 对_name2进行赋值 */ public void set_name2(boolean _name2) { this._name2 = _name2; } /** * 获取 _pinyin2 * @return 返回 _pinyin2 */ public boolean is_pinyin2() { return _pinyin2; } /** * 设置 _pinyin2 * @param 对_pinyin2进行赋值 */ public void set_pinyin2(boolean _pinyin2) { this._pinyin2 = _pinyin2; } /** * 获取 _mobile2 * @return 返回 _mobile2 */ public boolean is_mobile2() { return _mobile2; } /** * 设置 _mobile2 * @param 对_mobile2进行赋值 */ public void set_mobile2(boolean _mobile2) { this._mobile2 = _mobile2; } /** * 获取 _credentials2 * @return 返回 _credentials2 */ public boolean is_credentials2() { return _credentials2; } /** * 设置 _credentials2 * @param 对_credentials2进行赋值 */ public void set_credentials2(boolean _credentials2) { this._credentials2 = _credentials2; } /** * 获取 _address2 * @return 返回 _address2 */ public boolean is_address2() { return _address2; } /** * 设置 _address2 * @param 对_address2进行赋值 */ public void set_address2(boolean _address2) { this._address2 = _address2; } /** * 获取 _email2 * @return 返回 _email2 */ public boolean is_email2() { return _email2; } /** * 设置 _email2 * @param 对_email2进行赋值 */ public void set_email2(boolean _email2) { this._email2 = _email2; } /** * 获取 _hkmlp2 * @return 返回 _hkmlp2 */ public boolean is_hkmlp2() { return _hkmlp2; } /** * 设置 _hkmlp2 * @param 对_hkmlp2进行赋值 */ public void set_hkmlp2(boolean _hkmlp2) { this._hkmlp2 = _hkmlp2; } /** * 获取 _tlp2 * @return 返回 _tlp2 */ public boolean is_tlp2() { return _tlp2; } /** * 设置 _tlp2 * @param 对_tlp2进行赋值 */ public void set_tlp2(boolean _tlp2) { this._tlp2 = _tlp2; } /** * 获取 _mtp2 * @return 返回 _mtp2 */ public boolean is_mtp2() { return _mtp2; } /** * 设置 _mtp2 * @param 对_mtp2进行赋值 */ public void set_mtp2(boolean _mtp2) { this._mtp2 = _mtp2; } /** * 获取 _passport2 * @return 返回 _passport2 */ public boolean is_passport2() { return _passport2; } /** * 设置 _passport2 * @param 对_passport2进行赋值 */ public void set_passport2(boolean _passport2) { this._passport2 = _passport2; } /** * 获取 _name3 * @return 返回 _name3 */ public boolean is_name3() { return _name3; } /** * 设置 _name3 * @param 对_name3进行赋值 */ public void set_name3(boolean _name3) { this._name3 = _name3; } /** * 获取 _pinyin3 * @return 返回 _pinyin3 */ public boolean is_pinyin3() { return _pinyin3; } /** * 设置 _pinyin3 * @param 对_pinyin3进行赋值 */ public void set_pinyin3(boolean _pinyin3) { this._pinyin3 = _pinyin3; } /** * 获取 _mobile3 * @return 返回 _mobile3 */ public boolean is_mobile3() { return _mobile3; } /** * 设置 _mobile3 * @param 对_mobile3进行赋值 */ public void set_mobile3(boolean _mobile3) { this._mobile3 = _mobile3; } /** * 获取 _credentials3 * @return 返回 _credentials3 */ public boolean is_credentials3() { return _credentials3; } /** * 设置 _credentials3 * @param 对_credentials3进行赋值 */ public void set_credentials3(boolean _credentials3) { this._credentials3 = _credentials3; } /** * 获取 _address3 * @return 返回 _address3 */ public boolean is_address3() { return _address3; } /** * 设置 _address3 * @param 对_address3进行赋值 */ public void set_address3(boolean _address3) { this._address3 = _address3; } /** * 获取 _email3 * @return 返回 _email3 */ public boolean is_email3() { return _email3; } /** * 设置 _email3 * @param 对_email3进行赋值 */ public void set_email3(boolean _email3) { this._email3 = _email3; } /** * 获取 _hkmlp3 * @return 返回 _hkmlp3 */ public boolean is_hkmlp3() { return _hkmlp3; } /** * 设置 _hkmlp3 * @param 对_hkmlp3进行赋值 */ public void set_hkmlp3(boolean _hkmlp3) { this._hkmlp3 = _hkmlp3; } /** * 获取 _tlp3 * @return 返回 _tlp3 */ public boolean is_tlp3() { return _tlp3; } /** * 设置 _tlp3 * @param 对_tlp3进行赋值 */ public void set_tlp3(boolean _tlp3) { this._tlp3 = _tlp3; } /** * 获取 _mtp3 * @return 返回 _mtp3 */ public boolean is_mtp3() { return _mtp3; } /** * 设置 _mtp3 * @param 对_mtp3进行赋值 */ public void set_mtp3(boolean _mtp3) { this._mtp3 = _mtp3; } /** * 获取 _passport3 * @return 返回 _passport3 */ public boolean is_passport3() { return _passport3; } /** * 设置 _passport3 * @param 对_passport3进行赋值 */ public void set_passport3(boolean _passport3) { this._passport3 = _passport3; } /** * 获取 _name * @return 返回 _name */ public boolean is_name() { return _name; } /** * 获取 _person * @return 返回 _person */ public Person get_person() { return _person; } /** * 设置 _person * @param 对_person进行赋值 */ public void set_person(Person _person) { this._person = _person; } /** * 设置 _name * @param 对_name进行赋值 */ public void set_name(boolean _name) { this._name = _name; } /** * 获取 _pinyin * @return 返回 _pinyin */ public boolean is_pinyin() { return _pinyin; } /** * 设置 _pinyin * @param 对_pinyin进行赋值 */ public void set_pinyin(boolean _pinyin) { this._pinyin = _pinyin; } /** * 获取 _mobile * @return 返回 _mobile */ public boolean is_mobile() { return _mobile; } /** * 设置 _mobile * @param 对_mobile进行赋值 */ public void set_mobile(boolean _mobile) { this._mobile = _mobile; } /** * 获取 _credentials * @return 返回 _credentials */ public boolean is_credentials() { return _credentials; } /** * 设置 _credentials * @param 对_credentials进行赋值 */ public void set_credentials(boolean _credentials) { this._credentials = _credentials; } /** * 获取 _address * @return 返回 _address */ public boolean is_address() { return _address; } /** * 设置 _address * @param 对_address进行赋值 */ public void set_address(boolean _address) { this._address = _address; } /** * 获取 _email * @return 返回 _email */ public boolean is_email() { return _email; } /** * 设置 _email * @param 对_email进行赋值 */ public void set_email(boolean _email) { this._email = _email; } /** * 获取 _hkmlp * @return 返回 _hkmlp */ public boolean is_hkmlp() { return _hkmlp; } /** * 设置 _hkmlp * @param 对_hkmlp进行赋值 */ public void set_hkmlp(boolean _hkmlp) { this._hkmlp = _hkmlp; } /** * 获取 _tlp * @return 返回 _tlp */ public boolean is_tlp() { return _tlp; } /** * 设置 _tlp * @param 对_tlp进行赋值 */ public void set_tlp(boolean _tlp) { this._tlp = _tlp; } /** * 获取 _mtp * @return 返回 _mtp */ public boolean is_mtp() { return _mtp; } /** * 设置 _mtp * @param 对_mtp进行赋值 */ public void set_mtp(boolean _mtp) { this._mtp = _mtp; } /** * 获取 _passport * @return 返回 _passport */ public boolean is_passport() { return _passport; } /** * 设置 _passport * @param 对_passport进行赋值 */ public void set_passport(boolean _passport) { this._passport = _passport; } }
/* * 文 件 名: Person.java * 版 权: Copyright YYYY-YYYY, All rights reserved * 描 述: <描述> * 创 建 人: james * 创建时间: 2016年4月11日 */ package test; /** * <一句话功能简述> * * @author james * @version [V1.00, 2016年4月11日] * @see [相关类/方法] * @since V1.00 */ public class Person { public int id_p; public String name_p; public boolean isMen_p; public Character ch_p; public Float float_p; public Double double_p; public Long long_p; public Short short_p; public Byte byte_p; public Student student_p; /** * 获取 id_p * @return 返回 id_p */ public int getId_p() { return id_p; } /** * 设置 id_p * @param 对id_p进行赋值 */ public void setId_p(int id_p) { this.id_p = id_p; } /** * 获取 name_p * @return 返回 name_p */ public String getName_p() { return name_p; } /** * 设置 name_p * @param 对name_p进行赋值 */ public void setName_p(String name_p) { this.name_p = name_p; } /** * 获取 isMen_p * @return 返回 isMen_p */ public boolean isMen_p() { return isMen_p; } /** * 设置 isMen_p * @param 对isMen_p进行赋值 */ public void setMen_p(boolean isMen_p) { this.isMen_p = isMen_p; } /** * 获取 ch_p * @return 返回 ch_p */ public Character getCh_p() { return ch_p; } /** * 设置 ch_p * @param 对ch_p进行赋值 */ public void setCh_p(Character ch_p) { this.ch_p = ch_p; } /** * 获取 float_p * @return 返回 float_p */ public Float getFloat_p() { return float_p; } /** * 设置 float_p * @param 对float_p进行赋值 */ public void setFloat_p(Float float_p) { this.float_p = float_p; } /** * 获取 double_p * @return 返回 double_p */ public Double getDouble_p() { return double_p; } /** * 设置 double_p * @param 对double_p进行赋值 */ public void setDouble_p(Double double_p) { this.double_p = double_p; } /** * 获取 long_p * @return 返回 long_p */ public Long getLong_p() { return long_p; } /** * 设置 long_p * @param 对long_p进行赋值 */ public void setLong_p(Long long_p) { this.long_p = long_p; } /** * 获取 short_p * @return 返回 short_p */ public Short getShort_p() { return short_p; } /** * 设置 short_p * @param 对short_p进行赋值 */ public void setShort_p(Short short_p) { this.short_p = short_p; } /** * 获取 byte_p * @return 返回 byte_p */ public Byte getByte_p() { return byte_p; } /** * 设置 byte_p * @param 对byte_p进行赋值 */ public void setByte_p(Byte byte_p) { this.byte_p = byte_p; } /** * 获取 student_p * @return 返回 student_p */ public Student getStudent_p() { return student_p; } /** * 设置 student_p * @param 对student_p进行赋值 */ public void setStudent_p(Student student_p) { this.student_p = student_p; } }
/* * 文 件 名: Student.java * 版 权: Copyright YYYY-YYYY, All rights reserved * 描 述: <描述> * 创 建 人: james * 创建时间: 2016年4月12日 */ package test; /** * <一句话功能简述> * * @author james * @version [V1.00, 2016年4月12日] * @see [相关类/方法] * @since V1.00 */ public class Student { private Integer id_s; private String name_s; /** * 获取 id_s * @return 返回 id_s */ public Integer getId_s() { return id_s; } /** * 设置 id_s * @param 对id_s进行赋值 */ public void setId_s(Integer id_s) { this.id_s = id_s; } /** * 获取 name_s * @return 返回 name_s */ public String getName_s() { return name_s; } /** * 设置 name_s * @param 对name_s进行赋值 */ public void setName_s(String name_s) { this.name_s = name_s; } }
最后还有一个properties文件,key是带赋值的字段名,value是去赋值的字段名
_pinyin=pinyin _mobile=mobile _credentials=credentials _address=address _email=email _hkmlp=hkmlp _tlp=tlp _mtp=mtp _passport=passport _pinyin2=pinyin2 _mobile2=mobile2 _credentials2=credentials2 _address2=address2 _email2=email2 _hkmlp2=hkmlp2 _tlp2=tlp2 _mtp2=mtp2 _passport2=passport2 _pinyin3=pinyin3 _mobile3=mobile3 _credentials3=credentials3 _address3=address3 _email3=email3 _hkmlp3=hkmlp3 _tlp3=tlp3 _mtp3=mtp3 _passport3=passport3 _person=person id_p=id_p name_p=name_p isMen_p=isMen_p ch_p=ch_p float_p=float_p double_p=double_p long_p=long_p short_p=short_p byte_p=byte_p student_p=student_p id_s=id_s name_s=name_s
收工~
浙公网安备 33010602011771号