JpaRepository中new的方式產生新的對象,並配置好其構造函數
JPA對字段命名有一點規則,推薦使用駝峯式命名,如果下面的方法會報錯,並且沒有明確的報錯信息,請先看字段是否合法!!!!!
下面是實例代碼:
JpaRepository:
@Transactional
public interface PayeeDataRepo extends JpaRepository<PayeeData, String> {
@Query("select new com.stylefeng.guns.workday.bean.PayeeData(p.id,p.name,p.bankAccountNumberEncode,p.adhocPayeeID,p.isDomestic,p.bankAccountName ) from PayeeData p")
List<PayeeData> finddAllNoBankNumber();
}
PayeeData Bean:
public class PayeeData implements Serializable {
public PayeeData() {
}
public PayeeData(String id, String name, String bankAccountNumberEncode, String adhocPayeeID, Integer isDomestic, String bankAccountName) {
this.id = id;
this.name = name;
this.bankAccountNumberEncode = bankAccountNumberEncode;
this.adhocPayeeID = adhocPayeeID;
this.isDomestic = isDomestic;
this.bankAccountName = bankAccountName;
}
}