HAL Broswer未显示RequestMappings

时间:2018-07-04 13:50:10

标签: spring-boot spring-data spring-data-rest hal

我正在尝试对使用Spring Reactive消息流的SpringBoot应用程序使用HATEAOS。 我使用的HAL API浏览器无法显示card下的Links。这是我的控制器文件。

package com.ayman.SpringReactive.controllers;

import com.ayman.SpringReactive.dao.CardRepository;
import com.ayman.SpringReactive.entities.Card;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/cards")
public class CardController {
    private CardRepository repository;

    public CardController(CardRepository repository) {
        this.repository = repository;
    }

    @GetMapping
    public Flux<Card> getAllCards() {
        return repository.findAll();

    }

    @GetMapping("{id}")
    public Mono<Card> getCard(@PathVariable String id) {
        return repository.findById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Mono<Card> saveCard(@RequestBody Card card) {
        return repository.save(card);

    }

    @PutMapping("{id}")
    public Mono<ResponseEntity<Card>> updateCard(@PathVariable(value = "id") String id,
                                                       @RequestBody Card card) {
        return repository.findById(id)
                         .flatMap(existingCard -> {
                             existingCard.setRank(card.getRank());//setType
                             existingCard.setFirst(card.getFirst());//setWidth
                             existingCard.setLast(card.getLast());//setHeight
                             return repository.save(existingCard);
                         })
                         .map(updateCard -> new ResponseEntity<>(updateCard, HttpStatus.OK))
                         .defaultIfEmpty(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }

    @DeleteMapping("{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public Mono<ResponseEntity<Object>> deleteCard(@PathVariable(value = "id") String id) {
        return repository.deleteById(id)
                         .then(Mono.just(ResponseEntity.noContent().build()))
                         .defaultIfEmpty(ResponseEntity.notFound().build());
    }

    @DeleteMapping
    public Mono<Void> deleteAllCards() {
        return repository.deleteAll();
    }
}

我是否需要进行其他配置才能使其显示在Links标签中?

0 个答案:

没有答案