[Html] import java. lang. reflect. field; import java. text. parseException; import java. text. simpleDateFormat; import java. util. arrayList; import java. util. date; import java. util. hashMap; public class BeanUtil {/*** copy the same attribute * from src to des */public static void copyPropertys (Object src, Object des) {ArrayList <Field> srcFields = new ArrayList <Field> (); HashMap <String, Field> desFields = new HashMap <Strin G, Field> (); for (Field field Field: src. getClass (). getDeclaredFields () {srcFields. add (field) ;}for (Field field: des. getClass (). getDeclaredFields () {desFields. put (field. getName (), field) ;}for (Field srcfield: srcFields) {try {if (desFields. containsKey (srcfield. getName () {Field desField = desFields. get (srcfield. getName (); if (srcfield. getName (). equals ("serialVersionUID") {continue;} desField. setA Ccessible (true); srcfield. setAccessible (true); if (srcfield. getType ()! = DesField. getType () {if (srcfield. getType () = java. util. date. class | srcfield. getType () = java. SQL. date. class | srcfield. getType () = java. SQL. timestamp. class) & desField. getType () = java. lang. string. class) {java. util. date dates = (Date) srcfield. get (src); desField. set (des, formatDate (dates);} else {if (desField. getType () = java. util. date. class | desField. getType () = java. SQL. date. clas S | desField. getType () = java. SQL. timestamp. class) {java. util. date date = ToDate (String. valueOf (srcfield. get (src); desField. set (des, date);} else if (desField. getType () = java. lang. integer. class | desField. getType () = int. class) {Integer ints = java. lang. integer. valueOf (String. valueOf (srcfield. get (src); desField. set (des, ints);} else if (desField. getType () = java. lang. long. class) {java. Lang. long longs = java. lang. long. getLong (String. valueOf (srcfield. get (src); desField. set (des, longs);} else {desField. set (des, String. valueOf (srcfield. get (src) ;}} else {desField. set (des, srcfield. get (src);} desField. setAccessible (false); srcfield. setAccessible (false) ;}} catch (Exception e) {e. printStackTrace () ;}}/ *** convert the Date format into a String in the yyyy-MM-dd HH: mm: ss format */public static String formatDa Te (Date date) {if (date = null) return ""; SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); return df. format (date);}/*** convert the Date format to a String in yyyy-MM-dd HH: mm: ss format */public static Date ToDate (String date) throws ParseException {SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); return df. parse (date) ;}} import java. lang. reflect. field; import java. text. parseException; Import java. text. simpleDateFormat; import java. util. arrayList; import java. util. date; import java. util. hashMap; public class BeanUtil {/*** copy the same attribute * from src to des */public static void copyPropertys (Object src, Object des) {ArrayList <Field> srcFields = new ArrayList <Field> (); HashMap <String, Field> desFields = new HashMap <String, Field> (); for (Field field Field: src. getClass (). getDeclaredFields () {srcFields. add (f Ield);} for (Field field: des. getClass (). getDeclaredFields () {desFields. put (field. getName (), field) ;}for (Field srcfield: srcFields) {try {if (desFields. containsKey (srcfield. getName () {Field desField = desFields. get (srcfield. getName (); if (srcfield. getName (). equals ("serialVersionUID") {continue;} desField. setAccessible (true); srcfield. setAccessible (true); if (srcfield. getType ()! = DesField. getType () {if (srcfield. getType () = java. util. date. class | srcfield. getType () = java. SQL. date. class | srcfield. getType () = java. SQL. timestamp. class) & desField. getType () = java. lang. string. class) {java. util. date dates = (Date) srcfield. get (src); desField. set (des, formatDate (dates);} else {if (desField. getType () = java. util. date. class | desField. getType () = java. SQL. date. class | desField. getType () = java. SQL. timestamp. class) {java. util. date date = ToDate (String. valueOf (srcfield. get (src); desField. set (des, date);} else if (desField. getType () = java. lang. integer. class | desField. getType () = int. class) {Integer ints = java. lang. integer. valueOf (String. valueOf (srcfield. get (src); desField. set (des, ints);} else if (desField. getType () = java. lang. long. class) {java. lang. long longs = java. lang. long. getLong (String. valueOf (srcfield. get (src); desField. set (des, longs);} else {desField. set (des, String. valueOf (srcfield. get (src) ;}} else {desField. set (des, srcfield. get (src);} desField. setAccessible (false); srcfield. setAccessible (false) ;}} catch (Exception e) {e. printStackTrace () ;}}/ *** convert the Date format into a String in yyyy-MM-dd HH: mm: ss format */public static String formatDate (Date date Date) {if (date = null) return ""; SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); return df. format (date); www.2cto.com}/*** convert the Date format into a String in the yyyy-MM-dd HH: mm: ss format */public static Date ToDate (String date) throws ParseException {SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); return df. parse (date );}}