我正在尝试创建新的Project并制作简单的类,Master和Pet类.
这是我的大师班
package com.david.duck.model;
import java.util.Set;
import org.neo4j.ogm.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
@NodeEntity
public class Master {
@GraphId
private long id;
private String name;
@Relationship(type="OWNS")
@JsonIgnore
private Set<Pet> pets;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Pet> getPets() {
return pets;
}
public void setPets(Set<Pet> pets) {
this.pets = pets;
}
public Master(){
super();
}
} …
Run Code Online (Sandbox Code Playgroud) 我有一个对象数组:
var a = [
{"name": "BBB", "no": 2, "size1": [3], "size2": null },
{"name": "AAA", "no": 5, "size1": null, "size2": [1] },
{"name": "BBB", "no": 1, "size1": [2], "size2": null },
{"name": "AAA", "no": 4, "size1": null, "size2": [1] },
{"name": "BBB", "no": 1, "size1": null, "size2": [1] },
{"name": "AAA", "no": 5, "size1": [2], "size2": null },
{"name": "BBB", "no": 2, "size1": null, "size2": [1] },
];
Run Code Online (Sandbox Code Playgroud)
我想像这样排序,按name
升序排序,然后no
升序,然后按size1,如果它不为空.
起初,我可以对它进行排序name
和no
,但在那之后,我不知道如何排序size1 …
我像这样使用RestTemplate配置:
private RestTemplate createRestTemplate() throws Exception {
final String username = "admin";
final String password = "admin";
final String proxyUrl = "localhost";
final int port = 443;
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyUrl, port),
new UsernamePasswordCredentials(username, password));
HttpHost host = new HttpHost(proxyUrl, port, "https");
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setProxy(host).setDefaultCredentialsProvider(credsProvider).disableCookieManagement();
HttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);
return new RestTemplate(factory);
}
Run Code Online (Sandbox Code Playgroud)
这就是我的方法的工作方式:
public String receiveMessage(String message) {
try {
restTemplate = createRestTemplate();
ObjectMapper mapper = new ObjectMapper(); …
Run Code Online (Sandbox Code Playgroud) 我的 maven-sonar 设置有问题。我需要将所有项目文件包含在src/main/java和src/main/resources中,以便 SonarQube 将显示我所有文件的结果,但排除src/main/resources/static/file中的一些文件。对于测试路径,它已经默认设置在src/test/java
这就是我设置 POM.XML 的方式
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
<!-- Sonar static analysis / Jacoco code coverage -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>com.Example.wp.WpCoreApplication</start-class>
<java.version>1.8</java.version>
<sonar.sources>src/main/java, src/main/resources</sonar.sources>
<sonar.exclusions>src/main/resources/static/file</sonar.exclusions>
</properties>
<dependencies>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.debatty</groupId> …
Run Code Online (Sandbox Code Playgroud) 我这里有一个样例项目
在样本数据,我尝试使用迁飞来实现与Neo4j的数据库数据库迁移。我可以使用H2数据库创建和插入普通SQL(我在示例项目中使用了H2数据库),但是我不知道如何使用Neo4j graphdatabase实现它。
应用程序启动时,我需要初始化数据。这就是我尝试设置迁移代码的方式:
public class V1_1__InitMaster implements SpringJdbcMigration {
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
/*
//Example using h2 database
jdbcTemplate.execute("CREATE TABLE Unit ("
+ "code VARCHAR(30),"
+ "name VARCHAR(30),"
+ "value DOUBLE"
+ ");");
jdbcTemplate.execute("INSERT INTO Unit ('ft','Feet',1);");
//How I can save my init data to neo4j database in here?
for(String[] unitString : initDataMaster.unitList){
//I got list unitList here
}
*/
}
}
Run Code Online (Sandbox Code Playgroud)
我读这页关于飞路,可与Neo4j的管理数据库迁移,而我看起来有些页面,大约有春节和Neo4j的迁飞整合解释。
我要问的是,如何保存初始化数据并使用Flyway对其进行管理,并将其与Neo4j和Spring集成在一起?