類似的結果可以用@QueryResult
- 創建領域類來保存返回的數據來實現。
- 與標註它
@QueryResult
實施例:(在科特林,這是我什麼手邊)
@QueryResult
open class Principal constructor(applicationToken: String,
profileId: String,
stageName: String,
showMeLaterDays: Float,
roles: Array<Role>)
{
var applicationToken: String
var profileId: String
var stageName: String
var showMeLaterDays: Float
@Convert(RoleArrayAttributeConverter::class)
var roles: Array<Role>
init
{
this.applicationToken = applicationToken
this.profileId = profileId
this.stageName = stageName
this.showMeLaterDays = showMeLaterDays
this.roles = roles
}
//Provide a default constructor for OGM
constructor() : this(applicationToken = "", profileId = "", stageName = "", showMeLaterDays = 0f,
roles = emptyArray())
}
然後用庫用它作爲如下:
@Query("MATCH (n:CandidateProfile {applicationToken: {0} })
RETURN n.id as profileId, n.applicationToken as applicationToken, n.stageName as stageName, n.showMeLaterDays as showMeLaterDays, n.roles as roles;")
fun findByApplicationToken(token: String): Principal?
- 請注意節點屬性返回與類字段名稱對應的方式。
- 功能結果也可以做到這一點。
注意:更多地道的Kotlin POJO請參考:https://github.com/neo4j-examples/movies-kotlin-spring-data-neo4j –