📄 category.java
字号:
/*
* Copyright 2006 Borys Burnayev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rdacorp.petstore.domain;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
* @author Borys Burnayev
*/
@Entity
@Table(name = "product_category")
public class Category {
private Integer categoryId;
private String code;
private String name;
private String description;
private String briefDescription;
private String imagePath;
private Collection<Product> products;
public Category(String code, String name, String description, String imagePath) {
this.code = code;
this.name = name;
this.description = description;
this.imagePath = imagePath;
}
public Category() {
}
@Id
@Column(name = "product_category_sysid")
public Integer getCategoryId() {
return this.categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
@Column(name = "product_category_abbr")
public String getCode() {
return this.code;
}
public void setCode(String productCategoryAbbr) {
this.code = productCategoryAbbr;
}
@Column(name = "product_category_nm")
public String getName() {
return this.name;
}
public void setName(String productCategoryNm) {
this.name = productCategoryNm;
}
@Column(name = "product_category_desc")
public String getDescription() {
return this.description;
}
public void setDescription(String productCategoryDesc) {
this.description = productCategoryDesc;
}
@Column(name = "brief_description")
public String getBriefDescription() {
return this.briefDescription;
}
public void setBriefDescription(String briefDescription) {
this.briefDescription = briefDescription;
}
@Column(name = "image_path")
public String getImagePath() {
return this.imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
@ManyToMany
@JoinTable(name = "product_category_map", joinColumns = { @JoinColumn(name = "product_category_sysid") }, inverseJoinColumns = { @JoinColumn(name = "product_sysid") })
public Collection<Product> getProducts() {
return this.products;
}
public void setProducts(Collection<Product> products) {
this.products = products;
}
public String toString() {
String id = categoryId != null ? categoryId.toString() : "<no ID>";
return "Category " + id + ":\nCode: " + code + "\nName: " + name + "\nDescription: " + description
+ "\nImage Path: " + imagePath + "\n";
}
public boolean equals(Object object) {
if (!(object instanceof Category))
return false;
Category category = (Category) object;
return code.equals(category.getCode());
}
public int hashCode() {
return code.hashCode();
}
public static Category findByID(Collection<Category> categories, Integer categoryID) {
if (categories != null) {
for (Category category : categories) {
Integer id = category.getCategoryId();
if (id.equals(categoryID)) {
return category;
}
}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -