解决复合主键
解決復(fù)合主鍵
使用@IdClass(BzdmKey.class)注解
package entity.po;import javax.persistence.*;/*** @Package main.java.pojo* @Description BZDM對象的pojo類* @Author zhaohuaqing*/ @Entity @Table(name = "ts_bzdm") @IdClass(BzdmKey.class) public class Bzdm {/*** 種類*/@Idprivate String kind;/*** 標(biāo)題*/@Columnprivate String bt;/*** 代碼*/@Idprivate String code;/*** 名稱*/@Columnprivate String mc;/*** 是否禁用,默認(rèn)0*/@Columnprivate String sfjy;/*** 排序號*/@Columnprivate Integer pxh;public String getKind() {return kind;}public void setKind(String kind) {this.kind = kind;}public String getBt() {return bt;}public void setBt(String bt) {this.bt = bt;}public String getCode() {return code;}public void setCode(String code) {this.code = code;}public String getMc() {return mc;}public void setMc(String mc) {this.mc = mc;}public String getSfjy() {return sfjy;}public void setSfjy(String sfjy) {this.sfjy = sfjy;}public Integer getPxh() {return pxh;}public void setPxh(Integer pxh) {this.pxh = pxh;}@Overridepublic String toString() {return "Bzdm{" +"kind='" + kind + '\'' +", bt='" + bt + '\'' +", code='" + code + '\'' +", mc='" + mc + '\'' +", sfjy='" + sfjy + '\'' +", pxh=" + pxh +'}';} } package entity.po;import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import java.io.Serializable; /*** @Package entity.po* @Description 解決主鍵重復(fù)問題* @Author zhaohuaqing*/ @Entity @Table(name = "ts_bzdm") public class BzdmKey implements Serializable {/*** @Fields serialVersionUID :1L*/private static final long serialVersionUID = 1L;/*** 種類*/@Idprivate String kind;/*** 代碼*/@Idprivate String code;public BzdmKey() {}public BzdmKey(String kind, String code) {this.kind = kind;this.code = code;}public static long getSerialVersionUID() {return serialVersionUID;}public String getKind() {return kind;}public void setKind(String kind) {this.kind = kind;}public String getCode() {return code;}public void setCode(String code) {this.code = code;}@Overridepublic String toString() {return "BzdmKey{" +"kind='" + kind + '\'' +", code='" + code + '\'' +'}';}/*** 覆蓋hashCode方法,必須要有*/@Overridepublic int hashCode() {final int PRIME = 31;int result = 1;result = PRIME * result + (kind == null ? 0 : kind.hashCode());result = PRIME * result + (code == null ? 0 : code.hashCode());return result;}/*** 覆蓋equals方法,必須要有*/@Overridepublic boolean equals(Object obj) {if (this == obj) {return true;}if (obj == null) {return false;}if (!(obj instanceof BzdmKey)) {return false;}BzdmKey objKey = (BzdmKey) obj;if (kind.equalsIgnoreCase(objKey.kind) && code.equalsIgnoreCase(objKey.code)) {return true;} else {return false;}}} 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
- 上一篇: 前端获取当前url路径
- 下一篇: jQuery 事件 - ready()