1.JPQL语句这样写的:
@Repositorypublic interface IEntitlementRelevantEntitlementViewRepository extends JpaRepository<RelevantEntitlementView, String>
{
/**
*
* Title: findRelevantEntitlementViewByEntlGuid Description: through entitlement guid getting
* RelevantEntitlementViews
*
* @param entitlementGuid
* @return List<RelevantEntitlementView>
*/
@Query(value = "select new com.sap.csc.ems.admin.model.dto.entitlement.repository.RelevantEntlViewResponseDto(T.entitlementNo, T.entitlementType, T.sourceDocNo, T.sourceItemNo, T.relevantEntlPKView.relation, T.relevantEntlPKView.relevantEntlGuid)"
+ " from RelevantEntitlementView T where T.relevantEntlPKView.guid = ?1 and T.relevantEntlPKView.langCode = ?2")
List<RelevantEntlViewResponseDto> findRelevantEntitlementViewsByEntlGuid(String entitlementGuid, String langCode);
}
2.接收的Dto定义这样的:
public class RelevantEntlViewResponseDto implements Serializable, Comparable<RelevantEntlViewResponseDto>
{
private static final long serialVersionUID = 2684804377793829074L;
private Long entitlementNo;
private String entitlementType;
private String sourceDocNo;
private String sourceItemNo;
private String relation;
private String guid;
public RelevantEntlViewResponseDto()
{
super();
}
public RelevantEntlViewResponseDto(Long entitlementNo, String entitlementType, String sourceDocNo, String sourceItemNo, String relation,
String guid)
{
super();
this.entitlementNo = entitlementNo;
this.entitlementType = entitlementType;
this.sourceDocNo = sourceDocNo;
this.sourceItemNo = sourceItemNo;
this.relation = relation;
this.guid = guid;
}
@Override
public int compareTo(RelevantEntlViewResponseDto responseDto)
{
//return this.getEntitlementNo().compareTo(responseDto.getEntitlementNo());
return this.entitlementNo > responseDto.getEntitlementNo() ? 1 : -1;
}
}
3.RelevantEntitlementView 的定义:
@Entity(name = "")
@Table(name = "")
public class RelevantEntitlementView implements Serializable
{
private static final long serialVersionUID = -2203166632368793389L;
@Column(name = HanaDbColumnConstants.ENTITLEMENT_TYPE)
private String entitlementType;
@Column(name = HanaDbColumnConstants.RELEVANT_ENTITLEMENT_NO)
private long entitlementNo;
@Column(name = HanaDbColumnConstants.RELEVANT_ENTITLEMENT_REF_DOC_NO)
private String sourceDocNo;
@Column(name = HanaDbColumnConstants.RELEVANT_ENTITLEMENT_REF_ITEM_NO)
private String sourceItemNo;
@EmbeddedId
private RelevantEntitlementPKView relevantEntlPKView;
}
4.RelevantEntitlementPKView 定义:
@Embeddable
public class RelevantEntitlementPKView implements Serializable
{
private static final long serialVersionUID = -1335267199925253148L;
@Column(name = HanaDbColumnConstants.ENTITLEMENT_GUID, nullable = false)
private String guid;
@Column(name = HanaDbColumnConstants.RELEVANT_ENTITLEMENT_GUID, nullable = false)
private String relevantEntlGuid;
@Column(name = HanaDbColumnConstants.RELATION)
private String relation;
}
这样就不用在通过view去接收之后再get,set进dto。通过构造函数直接用Dto接收更加方便!