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@SuppressWarnings("exports")
020@Controller
021public class HelloController {
022
023        /**
024         * Placate JDK 18 Javadoc
025         */
026        public HelloController() {
027        }
028
029        /**
030         * Here we use JStachio runtime to resolve the renderer (in this case we are calling
031         * them Views) via Springs Http Message Converter.
032         * @apiNote Notice that the method has to be annotated with
033         * <code>&#64;ResponseBody</code>.
034         * @return the model that will be used to find the correct view and then rendered
035         * using that view
036         * @see JStachioHttpMessageConverter
037         */
038        @GetMapping(value = "/")
039        @ResponseBody
040        public HelloModel hello() {
041                return new HelloModel("Spring Boot WebFlux is now JStachioed!");
042        }
043
044        /**
045         * Here we use {@link JStacheInterfaces} to make our model implement a Spring View to
046         * support the traditional servlet MVC approach. The model will use the static
047         * jstachio singleton that will be the spring one.
048         * <p>
049         * This approach has pros and cons. It makes your models slightly coupled to Spring
050         * MVC but allows you to return different views if say you had to redirect on some
051         * inputs ({@link RedirectView}).
052         *
053         * @apiNote Notice that the return type is {@link View}.
054         * @return the model that will be used as View
055         * @see JStachioHttpMessageConverter
056         */
057        @GetMapping(value = "/mvc")
058        public View mvc() {
059                return JStachioModelView.of(new HelloModel("Spring Boot WebFlux View is now JStachioed!"));
060        }
061
062}