【发布时间】:2021-06-18 06:25:26
【问题描述】:
我有以下枚举:
enum class Difficulty {
EASY, MEDIUM, HARD
}
我的 Rest API 以以下方式工作:我有类,每个类都有一个 classManagementService,它有助于列出每个响应。像这样:
@Service
class RecipeManagementService (@Autowired private val recipeRepository: RecipeRepository,
private val addRecipeRequestTransformer: AddRecipeRequestTransformer) {
fun findAll(): List<RecipeResponse> = this.recipeRepository.findAll().map(Recipe::toRecipeResponse)
RecipeResource.kt
@RestController
@RequestMapping(value = [BASE_RECIPE_URL])
class RecipeResource(private val recipeManagementService: RecipeManagementService)
{
@GetMapping
fun findAll(): ResponseEntity<List<RecipeResponse>> = ResponseEntity.ok(this.recipeManagementService.findAll())
RecipeResponse.kt
data class RecipeResponse (var id:Long,
var name:String,
var ingredient:List<Ingredient>?,
var process:String?,
var category: List<Category>?,
var difficulty: Difficulty?)
我希望 /api/v1/difficulty 请求列出所有困难。有没有办法做到这一点?
【问题讨论】:
标签: json spring-boot rest kotlin enums