October 2018
Intermediate to advanced
982 pages
23h 29m
English
Having written the code to display comments, it's now time to craft the bits to create them.
We've already seen the changes to our template adding an HTML form to write a comment. Let's code the corresponding controller in the comments subpackage, as follows:
@Controller public class CommentController { private final RabbitTemplate rabbitTemplate; public CommentController(RabbitTemplate rabbitTemplate) { this.rabbitTemplate = rabbitTemplate; } @PostMapping("/comments") public Mono<String> addComment(Mono<Comment> newComment) { return newComment.flatMap(comment -> Mono.fromRunnable(() -> rabbitTemplate .convertAndSend( "learning-spring-boot", "comments.new", comment))) .log("commentService-publish") .then(Mono.just("redirect:/")); ...Read now
Unlock full access