001package io.jstach.opt.spring.webflux.example.hello; 002 003import org.springframework.stereotype.Controller; 004import org.springframework.web.bind.annotation.GetMapping; 005import org.springframework.web.bind.annotation.ResponseBody; 006import org.springframework.web.reactive.result.view.RedirectView; 007import org.springframework.web.reactive.result.view.View; 008 009import io.jstach.jstache.JStacheInterfaces; 010import io.jstach.opt.spring.web.JStachioHttpMessageConverter; 011import io.jstach.opt.spring.webflux.JStachioModelView; 012 013/** 014 * Example hello world controller using different ways to use JStachio for web 015 * development. 016 * 017 * @author agentgt 018 */ 019@Controller 020public class HelloController { 021 022 /** 023 * Placate JDK 18 Javadoc 024 */ 025 public HelloController() { 026 } 027 028 /** 029 * Here we use JStachio runtime to resolve the renderer (in this case we are calling 030 * them Views) via Springs Http Message Converter. 031 * @apiNote Notice that the method has to be annotated with 032 * <code>@ResponseBody</code>. 033 * @return the model that will be used to find the correct view and then rendered 034 * using that view 035 * @see JStachioHttpMessageConverter 036 */ 037 @GetMapping(value = "/") 038 @ResponseBody 039 public HelloModel hello() { 040 return new HelloModel("Spring Boot is now JStachioed!"); 041 } 042 043 /** 044 * Here we use {@link JStacheInterfaces} to make our model implement a Spring View to 045 * support the traditional servlet MVC approach. The model will use the static 046 * jstachio singleton that will be the spring one. 047 * <p> 048 * This approach has pros and cons. It makes your models slightly coupled to Spring 049 * MVC but allows you to return different views if say you had to redirect on some 050 * inputs ({@link RedirectView}). 051 * 052 * @apiNote Notice that the return type is {@link View}. 053 * @return the model that will be used as View 054 * @see JStachioHttpMessageConverter 055 */ 056 @GetMapping(value = "/webflux") 057 public View mvc() { 058 return JStachioModelView.of(new HelloModel("Spring Boot WebFlux is now JStachioed!")); 059 } 060 061}