Просмотр исходного кода

修改componentGoods主键方式

suntg 8 лет назад
Родитель
Сommit
68fc8b7cae

+ 2 - 1
src/main/java/com/uas/platform/b2c/prod/product/component/dao/ComponentGoodsDao.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.prod.product.component.dao;
 
 import java.util.List;
 
+import com.uas.platform.b2c.prod.product.component.modal.ComponentGoodsId;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
@@ -12,7 +13,7 @@ import com.uas.platform.b2c.prod.product.component.modal.ComponentGoods;
 
 @Repository
 public interface ComponentGoodsDao extends JpaSpecificationExecutor<ComponentGoods>,
-		JpaRepository<ComponentGoods, Long> {
+		JpaRepository<ComponentGoods, ComponentGoodsId> {
 
 	/**
 	 * 按id获取产品信息,并且按照给定的id的顺序

+ 3 - 17
src/main/java/com/uas/platform/b2c/prod/product/component/modal/ComponentGoods.java

@@ -23,26 +23,20 @@ import java.util.List;
  */
 @Entity
 @Table(name = "v$product$cmpgoods")
+@IdClass(ComponentGoodsId.class)
 public class ComponentGoods implements Serializable {
 
-	private static final long serialVersionUID = 1L;
-
-	/**
-	 * 主键id 因为在视图中使用的rowid,所以这里id为String类型
-	 */
-	@Id
-	@Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
-	private Long id;
-
 	/**
 	 * product$component的主键
 	 */
+	@Id
 	@Column(name = "cmp_id")
 	private Long cmpId;
 
 	/**
 	 * trade$goods的主键
 	 */
+	@Id
 	@Column(name = "go_id")
 	private Long goId;
 
@@ -260,14 +254,6 @@ public class ComponentGoods implements Serializable {
 	@Column(name = "go_storename")
 	private String storeName;
 
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
 	public Long getCmpId() {
 		return cmpId;
 	}

+ 46 - 0
src/main/java/com/uas/platform/b2c/prod/product/component/modal/ComponentGoodsId.java

@@ -0,0 +1,46 @@
+package com.uas.platform.b2c.prod.product.component.modal;
+
+import java.io.Serializable;
+
+public class ComponentGoodsId implements Serializable{
+
+    private Long cmpId;
+    private Long goId;
+
+    public Long getCmpId() {
+        return cmpId;
+    }
+
+    public void setCmpId(Long cmpId) {
+        this.cmpId = cmpId;
+    }
+
+    public Long getGoId() {
+        return goId;
+    }
+
+    public void setGoId(Long goId) {
+        this.goId = goId;
+    }
+
+    public ComponentGoodsId() {
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ComponentGoodsId that = (ComponentGoodsId) o;
+
+        if (cmpId != null ? !cmpId.equals(that.cmpId) : that.cmpId != null) return false;
+        return goId != null ? goId.equals(that.goId) : that.goId == null;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = cmpId != null ? cmpId.hashCode() : 0;
+        result = 31 * result + (goId != null ? goId.hashCode() : 0);
+        return result;
+    }
+}

+ 3 - 0
src/main/java/com/uas/platform/b2c/prod/product/component/service/impl/ComponentGoodsServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2c.prod.product.component.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2c.common.search.rpc.service.SearchService;
 import com.uas.platform.b2c.prod.product.component.dao.ComponentGoodsDao;
 import com.uas.platform.b2c.prod.product.component.modal.ComponentGoods;
@@ -101,6 +102,8 @@ public class ComponentGoodsServiceImpl implements ComponentGoodsService {
 		if(totalElements > new Long(maxExposeInfo).longValue()) {
 			totalElements = maxExposeInfo;
 		}
+		System.out.println(JSON.toJSON(info));
+		System.out.println(JSON.toJSON(page.getContent()));
 		page = new PageImpl<>(page.getContent(), info, totalElements);
 		return page;
 	}