Search⌘ K

Tiptoeing Into Templates

Explore how to build reactive web pages using Thymeleaf templates within a Spring Boot WebFlux framework. Understand the use of reactive controllers that return template names wrapped in Mono objects. This lesson guides you through creating simple, static HTML templates and configuring Spring Boot to serve them reactively, laying the foundation for dynamic web app development.

We'll cover the following...

Templates

So far, we’ve built a web controller that generates streaming JSON. That will help us get oriented with the reactive web. That’s not all that’s needed to build web services. We often need to serve web pages. Therefore, we should turn to template libraries. When it comes to reactive programming, ThymeleafThymleaf fully supports Reactive Streams.

It also has the bonus feature of being 100% HTML-compliant.

Check out the basic example below:

Java
package com.greglturnquist.hackingspringboot.reactive;
import reactor.core.publisher.Mono;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HomeController {
@GetMapping
Mono<String> home() {
return Mono.just("home");
}
}

There’s not too much to analyze here:

  • The @Controller indicates that this is a Spring web controller, but it’s based upon templates ...