程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<String, Set <String>> 使用 @CompositeProperty 注释大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<@R_944_10495@ng, Set <@R_944_10495@ng>> 使用 @CompositeProperty 注释?

开发过程中遇到在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<@R_944_10495@ng, Set <@R_944_10495@ng>> 使用 @CompositeProperty 注释的问题如何解决?下面主要结合日常开发的经验,给出你关于在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<@R_944_10495@ng, Set <@R_944_10495@ng>> 使用 @CompositeProperty 注释的解决方法建议,希望对你解决在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<@R_944_10495@ng, Set <@R_944_10495@ng>> 使用 @CompositeProperty 注释有所启发或帮助;

我有一个关于在带有 Kotlin 和 Neo4j 的 Spring Boot 应用程序中将 @CompositeProperty 用于 Map> 的问题。

plugins {
    ID("org.springframework.boot") version "2.5.0-SNAPSHOT"
    ID("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.4.30"
    kotlin("plugin.spring") version "1.4.30"
}

dependencIEs {
    implementation("org.springframework.boot:spring-boot-starter-data-neo4j")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("io.projectreactor:reactor-test")
}

我想在实体中有一个 Map,它包含一个字符串作为键和一组字符串作为值 (Map>)。 (它是类中的最后一个属性)

@Node("Skill")
data class Skill(

  @ID
  @GeneratedValue
  @JsonIgnore
  val ID: Long?,@Property("uuID")
  val uuID: UUID?,@CompositeProperty
  val description: Map<@R_944_10495@ng,Set<@R_944_10495@ng>>?,

路由器:

@SpringBootApplication
internal class SkillApplication {

    @Bean
    fun route(handler: SkillHandler) = router {
        GET("$SKILL_ROUTE/$ID_PATH_PATTERN",handler::findByUuID)
        GET(SKILL_ROUTE,handler::findAll)
        POST(SKILL_ROUTE,handler::create)
    }

    companion object {
        const val SKILL_ROUTE = "/skill"
        const val ID_PATH_VAR = "ID"
        const val ID_PATH_PATTERN = "{$ID_PATH_VAR:${ID_PATTERN}}"
    }

}

fun main(args: Array<@R_944_10495@ng>) {
    runApplication<SkillApplication>(*args)
}

处理程序:

@Component
internal class SkillHandler(val service: SkillservicE) {

  fun findAll(request: Serverrequest): Mono<ServerResponse> {
    return ok().body(service.findAll())
  }

fun create(request: Serverrequest): Mono<ServerResponse> {
    return request.bodyToMono<Skill>()
      .flatMap {
        service.create(it).flatMap { skill ->
          ok().body(skill.toMono())
            .switchIfEmpty(badrequest().build())
        }
      }
  }

服务层(关系“层次结构”只是关系的第一个测试):

internal class Skillservice(val repo: SkillRepository) {

  fun findAll() = repo.findAll()

fun create(skillrequest: Skill): Mono<Skill> {
    val skill2 = Skill(
      null,UUID.randomUUID(),mapOf("en" to setof("english description")),emptySet()
    )
    val hIErarchy: Set<HIErarchy> = setof(HIErarchy(null,skill2))
    val saveSkill: Skill = skillrequest.copy(uuID = UUID.randomUUID(),hIErarchy = hIErarchy)
    return repo.save(saveSkill)

我在查看数据库浏览器上存储的信息时注意到的是,地图存储在属性下,这不应该是这种情况。

{
  "IDentity": 12,"labels": [
    "Skill"
  ],"propertIEs": {
"description.en": [
      "english description 2","english description 1"
    ],"uuID": "2e7924c1-6e53-4faa-be93-8081107279f5"
  }
}

记录实际上应该是这样的

{
    "uuID": "eeaacee9-782a-42e9-b5a2-5bf2b837addc","description": {
        "en": [
            "english description 2","english description 1"
        ]

但是,当通过 rest 端点检索数据时,我收到以下错误消息

"status": 500,"error": "Internal Server Error","message": "JsON enCoding error: class org.neo4j.driver.internal.value.stringvalue cAnnot be cast to class java.lang.@R_944_10495@ng (org.neo4j.driver.internal.value.stringvalue is in un@R_419_6889@d module of loader 'app'; java.lang.@R_944_10495@ng is in module java.base of loader 'bootstrap'); nested exception is com.fasterxml.jackson.databind.JsonMapPingException: class org.neo4j.driver.internal.value.stringvalue cAnnot be cast to class java.lang.@R_944_10495@ng (org.neo4j.driver.internal.value.stringvalue is in un@R_419_6889@d module of loader 'app'; java.lang.@R_944_10495@ng is in module java.base of loader 'bootstrap') (through reference chain: java.util.ArrayList[0]->com.test.skill.entity.Skill[\"description\"]->java.util.HashMap[\"en\"]->java.util.linkedHashSet[0])",

我的猜测是我需要 Neo4jPersistentPropertyToMapConverter 接口。我的这个假设是否正确,具体实现方式如何?

非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<String, Set <String>> 使用 @CompositeProperty 注释全部内容,希望文章能够帮你解决在使用 Kotlin 和 Neo4j 的 Spring Boot 应用程序中为 Map<String, Set <String>> 使用 @CompositeProperty 注释所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。