codecamp

实体的继承

在项目开发时,如果多个实体中都有些共同的属性时,可以把共同的属性提取放在一个共同的父类实体中,其他实体只需继承共同实体,这样就减少了共同实体中属性的重复编写工作。这里把上面的实体Product中的id属性提取放到共同实体Common中去,修改如下

public class Common {
	private String id="";
	public String getId() 
	{
		if ((id==null)||("".equals(id))||("null".equalsIgnoreCase(id))) {
			id=UUID.randomUUID().toString();
		}
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
}

Product实体如下

public class Product extends Common
{
	private String name="";
	private float price=0;
	private String madeIn="";
	
	//getters/setters
}

这样Product实体就继承了Common实体中属性和使用了


编写实体和建表
添加数据
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }