未解决的参考由于接收器类型不匹配,以下候选者均不适用

时间:2019-03-07 13:32:16

标签: java intellij-idea kotlin

我正在使用简单的Kotlin 1.3版本。我的片段代码是:

import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*

@RestController 
@RequestMapping("fields") 
class FieldsController(private val fieldService: FieldService) { 
    @GetMapping 
    fun index() = fieldService.all() 

    @PostMapping 
    @ResponseStatus(HttpStatus.CREATED) 
    fun create(@RequestBody field: Field) = fieldService.add(field) 

    @GetMapping("{id}") // Тут мы говорим что это GET запрос с параметром в url (http://localhost/products/{id})
    @ResponseStatus(HttpStatus.FOUND)
    fun read(@PathVariable id: Int) = fieldService.get(id) <-- error

    @PutMapping("{id}")
    fun update(@PathVariable id: Int, @RequestBody field: Field) = fieldService.edit(id, field) 
    @DeleteMapping("{id}")
    fun delete(@PathVariable id: Field) = fieldService.remove(id)
}

因此,get中的错误看起来像这里的错误:

  

未解决的参考。由于接收器类型不匹配,以下候选者都不适用:   @InlineOnly公共内联运算符fun <@OnlyInputTypes K,V> Map.get(key:Int):???在kotlin.collections中定义   @SinceKotlin公共运算符fun MatchGroupCollection.get(name:String):MatchGroup吗?在kotlin.text中定义

我的构建Gradle是:

plugins {
    id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.21'
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'org.jetbrains.kotlin.jvm' version '1.3.21'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.3.21'
}

apply plugin: 'kotlin-jpa'
apply plugin: 'io.spring.dependency-management'

group = 'ru.playa.common'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-jersey'
    implementation 'io.springfox:springfox-swagger2:2.9.2'
    implementation 'io.springfox:springfox-swagger-ui:2.9.2'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencies {
    compile("org.springframework:spring-context:4.1.6.RELEASE")
}

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

0 个答案:

没有答案