我的情况是通过MySQL检索数据并将其保存在ArrayList对象中,我需要将同一个对象放入cypher查询中,并使用junit test`public class DummyTest {@Test@Rollback(true)public void checkMysqlConnection() { Connection connection = null; ResultSet tableDatasRsult = null; try { Class.forName("com.mysql.jdbc.Driver"); Properties properties = new Properties(); properties.setProperty("user", "root"); properties.setProperty("password", "root"); String url = "127.0.0.1:3306/unicity"; connection = DriverManager.getConnection("jdbc:mysql://" + url, properties); Assert.assertNotNull(connection); String sqlq = "select DIST_ID,PV_DATE,POST_DATE from odh"; PreparedStatement preparedStatement = connection.prepareStatement(sqlq); tableDatasRsult = preparedStatement.executeQuery(); ArrayList<OdhDO> odhDOs = new ArrayList<>(); while (tableDatasRsult.next()) { OdhDO odhDO = new OdhDO(); odhDO.setDistId(tableDatasRsult.getLong("DIST_ID")); odhDO.setPvDate(tableDatasRsult.getString("PV_DATE")); odhDO.setPostDate(tableDatasRsult.getString("POST_DATE")); odhDOs.add(odhDO); Map<String, Object> params = new HashMap<>(); params.put(odhDO.getDistId().toString(), odhDO); System.out.println(params); } } catch (ClassNotFoundException e) { System.out.println("MySql Driver Class Not Found Exception"); e.printStackTrace(); } catch (SQLException e) { System.out.println("Sql Exception"); e.printStackTrace(); } finally { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } }}@Test@Rollback(true)public void checkneo4jConnection(){ String URL= "http://localhost:7474"; Configuration configuration = new Configuration(); configuration.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL).setCredentials("neo4j", "admin"); String cypher = "MATCH (Distributor) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor"; Map<String, Object> params = new HashMap<>(); List<String> odhDOs = new ArrayList<>(); params.put("odhDOs", odhDOs); //add some names to the names list //params.put(key, value) }`在上述checkMysqlConnection()方法中的代码中,我已检索数据并将此数据保存在ArrayList odhDOs = new ArrayList ()对象中,我需要在密码查询中传递此Arraylist实例,但我不知道如何配置并从此类连接neo4j,以及如何在查询中传递此arraylist实例“在(odhDOs} RETURN分发服务器中,MATCH(分发服务器)WHERE分发服务器.DISTID” 请帮助配置neo4j的junit以及如何在cypher查询中传递数组实例..提前感谢... 最佳答案 如果您已根据OGM reference guide中的文档正确设置了所有内容,则应执行以下操作:@Testpublic void checkneo4jConnection(){ Configuration configuration = new Configuration(); configuration.driverConfiguration() .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver") .setURI("http://localhost:7474") .setCredentials("neo4j", "admin"); SessionFactory sessionFactory = new SessionFactory(configuration, "package.where.your.distributor.class.is"); Session session = sessionFactory.openSession(); String cypher = "MATCH (Distributor) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor"; Map<String, Object> params = new HashMap<>(); params.put("odhDOs", Arrays.asList(new String[] {"odhDO1", "odhDO2"}); // NOTE: If more than one result use session.query(). // If just one, use session.queryForObject() Iterable<Distributor> distributors = session.query(Distributor.class, cypher, params); for (Distributor distributor: distributors) { System.out.println(distributor.getDISTID()); }}关于mysql - 用于junit的neo4j配置,并在密码查询中传递arraylist实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40258450/ 10-11 02:48