package com.cn.rzx.base;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * 抽象的实体超类,专门用于继承
 */
public abstract class BaseEntity implements Serializable{
	private static final long serialVersionUID = -6391445021378844473L;

	public abstract Integer getId();

	public abstract void setId(Integer id) ;
	
	public String toString() {
		try {
			StringBuffer buffer = new StringBuffer();
			Class clazz = this.getClass();
			String simpleName = clazz.getSimpleName();
			buffer.append(simpleName);
			buffer.append("{");
			//
			Field[] fs = clazz.getDeclaredFields();
			Class ftype = null ;
			String fname = null ;
			Object fvalue = null ;
			for(Field f : fs){
				ftype = f.getType();
				fname = f.getName();
				f.setAccessible(true);
				fvalue = f.get(this);
				//是否是基本数据类型
				if((ftype.isPrimitive()
						||ftype == Integer.class
						||ftype == Long.class
						||ftype == Short.class
						||ftype == Boolean.class
						||ftype == Character.class
						||ftype == Double.class
						||ftype == Float.class
						||ftype == String.class)
						&& !Modifier.isStatic(f.getModifiers())
						){
					buffer.append(fname);
					buffer.append(":");
					buffer.append(fvalue);
					buffer.append(",");
				}
			}
			//
			buffer.append("{}");
			return buffer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
}
最近下载更多
1057148049  LV11 2021年12月6日
543666826  LV33 2021年11月18日
15281682932  LV9 2021年6月21日
xyy999  LV1 2021年5月26日
混的人6666  LV2 2020年8月1日
kkkxyh  LV13 2020年5月4日
18337281853  LV12 2020年4月29日
晓白1234  LV3 2020年4月27日
775794341  LV13 2020年4月17日
BlackHorse  LV1 2019年7月6日
最近浏览更多
WaZiN7  LV6 4月25日
wangsheng818  LV4 2月29日
微信网友_6802139027345408  LV2 2023年12月31日
李亮  LV19 2023年8月29日
1748938504  LV2 2023年6月30日
mu5532123  LV2 2023年6月15日
qwer123978ca  LV1 2022年12月20日
微信网友_6263159342649344  LV7 2022年12月16日
微信网友_6248713511227392  LV11 2022年12月5日
1743716295  LV4 2022年11月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友