【发布时间】:2016-02-29 20:09:55
【问题描述】:
我从来没有看到这个表格对我有帮助。我希望是现在。
在我的spring-boot中,我的数据库有两个主键
TransId 和 PrsnRef
现在,当我为名为 PersonCore 的数据库表创建实体时,我得到了 2 个类
PersonCore(众所周知,这包含所有其余数据)
/**
* The persistent class for the PERSON_CORE database table.
*
*/
@Entity
@Table(name="PERSON_CORE")
@NamedQuery(name="PersonCore.findAll", query="SELECT f FROM PersonCore f")
public class PersonCore implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private PersonCorePK id;
@Column(name="PRSN_AGE")
private BigDecimal prsnAge;
@Column(name="PRSN_AMER_INDIAN_ALASKA_NTV")
private String prsnAmerIndianAlaskaNtv;
@Column(name="PRSN_DOB")
private String prsnDob;
PersonCorePK(这有两个Id的transid和personref)
/**
* The primary key class for the PERSON_CORE database table.
*
*/
@Embeddable
public class PersonCorePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(name="TRANS_ID")
private String transId;
@Column(name="PRSN_REF")
private String prsnRef;
public FdshPersonCorePK() {
}
public String getTransId() {
return this.transId;
}
public void setTransId(String transId) {
this.transId = transId;
}
public String getPrsnRef() {
return this.prsnRef;
}
public void setPrsnRef(String prsnRef) {
this.prsnRef = prsnRef;
}
我正在尝试使用 spring-boot 创建一个 RESTFul 服务 我使用 @RepositoryRestResource(bla bla bla) 创建了存储库
@RepositoryRestResource(path = "person", collectionResourceRel = "FdshPersonHDR")
public interface PersonCoreRepository extends PagingAndSortingRepository<PersonCore, PersonCorePK> {
Collection<PersonCore > findAll();
Collection<PersonCore > findAllByIdTransIdAndIdPrsnRef(@Param("transid")String transId, @Param("prsnRef") String prsnRef);
}
Spring boot 太棒了,它可以很好地照顾我。 让我们看看...
当我尝试从数据库中获取所有记录时,一切都很好,除了最终链接是这样的
http://localhost:8080/person/com.----.Application.Methods.PersonCorePK@83e14116
这快把我逼疯了。我知道它会阅读我想要的内容,但不会准确地向我展示我需要的内容。我需要帮助弄清楚如何转换 "com.----.Application.Methods.PersonCorePK@83e14116" 。它实际上应该显示该记录的 transid。
请让我知道是否有任何方法可以将这两个复合键添加到该 o/p 格式中,因为我正在获取我想要的所有数据,除了这两个对我来说很重要的数据。我不确定我是否可以在单个实体中使用两个@Id。但我会检查一下。
【问题讨论】:
-
您的意思是“我想要在 PersonCorePK 类中合理地覆盖 toString() 方法”?
-
感谢您的快速响应先生,我想弄清楚是否有办法将“com.----.Application.Methods.PersonCorePK@83e14116”显示为 transID
标签: java spring rest spring-boot