0
{
"id": 109433,
"name": "test",
"value": [
"c"
]
}
具有節點上述予執行該交所以值包含 「a」 修改我的對象中, 「b」 而不是 「C」:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d ' {
"id": 109433,
"name": "test",
"value": [
"a","b"
]
}' 'http://localhost:8080/configs'
然後我執行一個GET來獲得所有節點
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/configs'
對於一些奇怪的原因,它會返回
{
"id": 109433,
"name": "test",
"value": [
"a",
"b",
"c"
]
}
如果我去我的web應用程序之外的Neo4j和查詢它,我會得到
{
"id": 109433,
"name": "test",
"value": [
"a","b"
]
}
所以只是要確定我有某種形式的數據污染像一個高速緩存運行某處停止服務器並再次打開服務器,然後再次獲得服務
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/configs'
return s:
{
"id": 109433,
"name": "test",
"value": [
"a",
"b",
]
}
所以現在「c」無處可見。 這裏是我使用
API
package io.swagger.api;
import io.swagger.annotations.*;
import io.swagger.model.Config;
import io.swagger.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping(value = "/configs", produces = {APPLICATION_JSON_VALUE})
@Api(value = "/configs", description = "the configs API")
public class ConfigsApi {
@Autowired
private ConfigService configService;
@ApiOperation(value = "", notes = "Gets `Config` objects. ", response = Config.class, responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful response", response = Config.class) })
@RequestMapping(value = "", produces = { "application/json" }, method = RequestMethod.GET)
public ResponseEntity<List<Config>> getAllConfigs() throws NotFoundException {
return new ResponseEntity<List<Config>>(configService.getAll(),HttpStatus.OK);
}
@ApiOperation(value = "", notes = "Creates/updates `Config` object. ", response = Void.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Void.class),
@ApiResponse(code = 400, message = "Invalid Config", response = Void.class) })
@RequestMapping(value = "", produces = { "application/json" }, method = RequestMethod.POST)
public ResponseEntity<Void> createConfigByKey(@ApiParam(value = "Updated user object" ,required=true) @RequestBody Config body) throws NotFoundException {
configService.merge(body);
return new ResponseEntity<Void>(HttpStatus.OK);
}
}
服務
package io.swagger.service;
import com.google.common.collect.Lists;
import io.swagger.model.Config;
import io.swagger.repository.ConfigRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class ConfigService {
@Autowired
private ConfigRepository configRepository;
public List<Config> getAll() {return Lists.newArrayList(configRepository.findAll());}
public void merge(Config c){configRepository.save(c);}
}
庫
package io.swagger.repository;
import io.swagger.model.Config;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;
public interface ConfigRepository extends GraphRepository<Config> {
}
Neo4j的配置
package io.swagger.configuration;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
@Configuration
@EnableNeo4jRepositories("io.swagger.*")
public class InventoryApiNeo4jConfiguration extends Neo4jConfiguration {
@Value("${neo4j.ogm.driver}")
private String driver;
@Value("${neo4j.ogm.URI}")
private String uri;
@Value("${neo4j.ogm.connection.pool.size}")
private int connectionPoolSize;
@Value("${neo4j.ogm.encryption.level}")
private String encryptionLevel;
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
configuration.driverConfiguration()
.setDriverClassName(driver)
.setURI(uri)
.setConnectionPoolSize(connectionPoolSize)
.setEncryptionLevel(encryptionLevel);
return configuration;
}
@Override
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "io.swagger");
}
}
代碼
雙龍
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-springboot-server</artifactId>
<packaging>jar</packaging>
<name>swagger-springboot-server</name>
<version>1.0.0</version>
<properties>
<springfox-version>2.4.0</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RC1</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
<scope>provided</scope>
</dependency>
<!-- Neo4J -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies><repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
你的配置節點實體是什麼樣的? – Luanne
@Luanne該節點是它有Id(長)的圖片。名稱(字符串),值(字符串數組)。問題是spring-data正在合併來自兩個對象的數據,而這在db上不會發生,所以我得到的代碼中的數據與數據庫無關 – Als