-2

I am new in java .I want to wrap the value of result in simple java class.

Iterator<Map<String,Object>> result=template.query(cypher,params);

Any Help will be Appreciated.

klaymen
  • 237
  • 2
  • 10
Anand
  • 429
  • 2
  • 17

1 Answers1

1

If you're using the template.query then you can either have it mapped to a domain entity or to the Map (and then you build the POJO yourself).

Otherwise, you can use a @Query in a repository and map it to a query result class. For example

 @Query("MATCH (user:User) WHERE user.gender={0} RETURN user.name AS UserName, user.gender AS UserGender, user.account as UserAccount, user.deposits as UserDeposits")
 Iterable<RichUserQueryResult> findUsersByGender(Gender gender);

@QueryResult
public class RichUserQueryResult {

    private Gender userGender; 
    private String userName;
    private BigInteger userAccount;
    private BigDecimal[] userDeposits;

    public Gender getUserGender() {
        return userGender;
    }

    public String getUserName() {
        return userName;
    }

    public BigInteger getUserAccount() {
        return userAccount;
    }

    public BigDecimal[] getUserDeposits() {
        return userDeposits;
    }
}
Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Listlist=new ArrayList(); /* for(Mapmap:result){ AdminSearchMapResult adminSearchMapResult=null; for(Map.Entryentry:map.entrySet()){ String key=entry.getKey(); Object value=entry.getValue(); System.out.println(key+"="+value); list.add(adminSearchMapResult); But it returns Null value.AdminSearchMapResult is my pojo class.i am using NEO4JTEMPLATE instance to excute the query. – Anand Jul 28 '15 at 11:59
  • 1
    Please check if your query really returns data – Luanne Jul 29 '15 at 08:06