标签:tab nat ati 不包含 ccf str c99 前端 logs
下面是经过特殊处理的entiey(实例)
package com.heren.his.domain.entity.drug; import javax.persistence.*; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; @Entity @Table(name="DRUG_PRESC_DETAIL_TEMP") @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class DrugPrescDetailTemp { @Id private DrugPrescDetailTempPK drugPrescDetailTempPK; @Column(name="PAYMENTS") private Double payments; @Column(name="DETAIL_NO") private String detailNo; @Column(name="ITEM_ID") private String itemId; @Transient
//指定属性或字段不是持久的。它用于为实体类、映射超类或可嵌入类的属性或字段进行注释。 private String administration; public DrugPrescDetailTemp() { } public DrugPrescDetailTemp(DrugPrescDetailTempPK drugPrescDetailTempPK, Double payments, String detailNo, String itemId) { this.drugPrescDetailTempPK = drugPrescDetailTempPK;this.payments = payments; this.detailNo = detailNo; this.itemId = itemId; } public DrugPrescDetailTempPK getDrugPrescDetailTempPK() { return drugPrescDetailTempPK; } public void setDrugPrescDetailTempPK(DrugPrescDetailTempPK drugPrescDetailTempPK) { this.drugPrescDetailTempPK = drugPrescDetailTempPK; } public Double getPayments() { return payments; } public void setPayments(Double payments) { this.payments = payments; } public String getDetailNo() { return detailNo; } public void setDetailNo(String detailNo) { this.detailNo = detailNo; } public String getItemId() { return itemId; } public void setItemId(String itemId) { this.itemId = itemId; } public void setAdministration(String administration) { this.administration = administration; } }
特殊之处在于红色部分标注的内容,含有@Id @Column的属性大家都知道是hibernate的注解,是用来和数据库字段一一对应的,而@Transient(指定属性或字段不是持久的。它用于实体类、映射超类或可嵌入类的属性或字段进行注解),所以在含有形参的构造函数里面不包含@Transient标注的属性,因为数据库表对应的字段不含有这个注解标注的属性,实例化的时候也不对这个属性赋值。
那什么时候才会用到这个属性呢?当前端要显示实体类中的一些属性,但是@Transient标注的这个属性并不能从数据库中得到,而是从另一个表里面取到,所以说在从数据库中得到这个实体类的对象时候,再从另一个表中取到这个属性,赋值给这个实体类的对象。这样一来前端需要显示的全部属性就得到了。如下:
public List<DrugPrescDetailTemp> queryInpPresc(String visitNo) {
List<DrugPrescDetailTemp> drugPrescDetailTempList = find(DrugPrescDetailTemp.class, "from DrugPrescDetailTemp dpdt where dpdt.prescNo =?1", prescNo); drugPrescDetailTempList.forEach(drugPrescDetailTemp -> { String administration = createQuery(String.class, "select administration from DrugOrderDetail dod where dod.orderId=?1", drugPrescDetailTemp.getItemNo()).getSingleResult(); drugPrescDetailTemp.setAdministration(administration); }); });
return drugPrescDetailTempList;
}
代码片段一和代码片段二中紫色的代码则是经过特殊处理和特殊操作的,这就是特殊处理的entity。
标签:tab nat ati 不包含 ccf str c99 前端 logs
原文地址:http://www.cnblogs.com/ms-grf/p/6795569.html