自动生成代码工具类用的的实体类

表的实体类

import java.io.Serializable;
import java.util.List;

/**
 * 表数据
 * 
 * @author 
 * @email 
 * @date 
 */
public class TableDO implements Serializable{
   //表的名称
   private String tableName;
   //表的备注
   private String comments;
   //表的主键
   private ColumnDO pk;
   //表的列名(不包含主键)
   private List<ColumnDO> columns;
   
   //类名(第一个字母大写),如:sys_user => SysUser
   private String className;
   //类名(第一个字母小写),如:sys_user => sysUser
   private String classname;
   
   public String getTableName() {
      return tableName;
   }
   public void setTableName(String tableName) {
      this.tableName = tableName;
   }
   public String getComments() {
      return comments;
   }
   public void setComments(String comments) {
      this.comments = comments;
   }
   public ColumnDO getPk() {
      return pk;
   }
   public void setPk(ColumnDO pk) {
      this.pk = pk;
   }
   public List<ColumnDO> getColumns() {
      return columns;
   }
   public void setColumns(List<ColumnDO> columns) {
      this.columns = columns;
   }
   public String getClassName() {
      return className;
   }
   public void setClassName(String className) {
      this.className = className;
   }
   public String getClassname() {
      return classname;
   }
   public void setClassname(String classname) {
      this.classname = classname;
   }
}

字段的实体类
/**
 * 列的属性
 * 
 * 
 */
public class ColumnDO {
	// 列名
	private String columnName;
	// 列名类型
	private String dataType;
	// 列名备注
	private String comments;

	// 属性名称(第一个字母大写),如:user_name => UserName
	private String attrName;
	// 属性名称(第一个字母小写),如:user_name => userName
	private String attrname;
	// 属性类型
	private String attrType;
	// auto_increment
	private String extra;

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getAttrname() {
		return attrname;
	}

	public void setAttrname(String attrname) {
		this.attrname = attrname;
	}

	public String getAttrName() {
		return attrName;
	}

	public void setAttrName(String attrName) {
		this.attrName = attrName;
	}

	public String getAttrType() {
		return attrType;
	}

	public void setAttrType(String attrType) {
		this.attrType = attrType;
	}

	public String getExtra() {
		return extra;
	}

	public void setExtra(String extra) {
		this.extra = extra;
	}
}

日期处理工具类

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理
 * 
 */
public class DateUtils {
	private final static Logger logger = LoggerFactory.getLogger(DateUtils.class);
	/** 时间格式(yyyy-MM-dd) */
	public final static String DATE_PATTERN = "yyyy-MM-dd";
	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

	public static String format(Date date) {
		return format(date, DATE_PATTERN);
	}

	public static String format(Date date, String pattern) {
		if (date != null) {
			SimpleDateFormat df = new SimpleDateFormat(pattern);
			return df.format(date);
		}
		return null;
	}

	public static String getTimeBefore(Date date) {
		Date now = new Date();
		long l = now.getTime() - date.getTime();
		long day = l / (24 * 60 * 60 * 1000);
		long hour = (l / (60 * 60 * 1000) - day * 24);
		long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
		long s = (l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		String r = "";
		if (day > 0) {
			r +=day + "天";
		}
		if (hour > 0) {
			r +=hour + "小时";
		}
		if (min > 0) {
			r +=min + "分";
		}
		if (s > 0) {
			r +=s + "秒";
		}
		r += "前";
		return r;
	}
}

自定义异常类

/**
 * 自定义异常

 */
public class BDException extends RuntimeException {
	private static final long serialVersionUID = 1L;
	
    private String msg;
    private int code = 500;
    
    public BDException(String msg) {
		super(msg);
		this.msg = msg;
	}
	
	public BDException(String msg, Throwable e) {
		super(msg, e);
		this.msg = msg;
	}
	
	public BDException(String msg, int code) {
		super(msg);
		this.msg = msg;
		this.code = code;
	}
	
	public BDException(String msg, int code, Throwable e) {
		super(msg, e);
		this.msg = msg;
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
	
	
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页