我正在使用 SPRING DATA REST 。我有这个控制器。
org.springframework.data.rest.webmvc.RepositoryRestController
import org.springframework.http.HttpMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController
@RepositoryRestController
class UserController {
@RequestMapping("/testing")
fun secured(): String {
return "Hello world"
}
@RequestMapping(method = arrayOf(RequestMethod.GET), value = "/scanners")
@ResponseBody
fun getProducers(): ResponseEntity<*> {
return ResponseEntity.ok<Any>("this is just a tedskljdksjdksjkdsjdkskdst")
}
}
我无法访问此端点,我总是得到 404 NOT FOUND ,当我更改为 @RestController 时,我可以点击路线。
答案 0 :(得分:0)
我找到了解决方案。如果您有用户实体,并且您的端点默认为 / users ,则如果您需要创建新端点,则必须以此方式命名为 / users / testing 你不会得到404错误。
@RepositoryRestController
class UserController {
@RequestMapping("/users/testing")
fun secured(): String {
return "Hello world"
}
@RequestMapping(method = arrayOf(RequestMethod.GET), value = "/scanners")
@ResponseBody
fun getProducers(): ResponseEntity<*> {
return ResponseEntity.ok<Any>("this is just a test")
}
}