Module io.jstach.opt.spring.example
Class HelloController
java.lang.Object
io.jstach.opt.spring.example.hello.HelloController
Example hello world controller using different ways to use JStachio for web
development.
- Author:
- agentgt
-
Field Summary
FieldsModifier and TypeFieldDescriptionSpring will inject this as the templates are component scanned as this projects moduleio.jstach.opt.spring.example
has a config that will add @Component
to all generated code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionentity()
Here we use aResponseEntity
which allows use to set status codes with our model to be rendered.hello()
Here we use JStachio runtime to resolve the renderer (in this case we are calling them Views) via Springs Http Message Converter.mvc()
Here we useJStacheInterfaces
to make our model implement a Spring View to support the traditional servlet MVC approach.Here we use the generated code directly and return aTemplateModel
which is analogous toModelAndView
.void
Here we use the wired renderer that does not have filtering and thus cannot use JMustache for dynamic editing of templates.
-
Field Details
-
view
Spring will inject this as the templates are component scanned as this projects moduleio.jstach.opt.spring.example
has a config that will add @Component
to all generated code.
-
-
Constructor Details
-
HelloController
public HelloController()Placate JDK 18 Javadoc
-
-
Method Details
-
hello
Here we use JStachio runtime to resolve the renderer (in this case we are calling them Views) via Springs Http Message Converter.- Returns:
- the model that will be used to find the correct view and then rendered using that view
- See Also:
- API Note
- Notice that the method has to be annotated with
@ResponseBody
.
-
templateModel
Here we use the generated code directly and return aTemplateModel
which is analogous toModelAndView
.- Returns:
- the template model pair that already has the template found.
- See Also:
- API Note
- Notice that the method has to be annotated with
@ResponseBody
.
-
entity
Here we use aResponseEntity
which allows use to set status codes with our model to be rendered.- Returns:
- a response entity.
- See Also:
-
mvc
Here we useJStacheInterfaces
to make our model implement a Spring View to support the traditional servlet MVC approach. The model will use the static jstachio singleton that will be the spring one.This approach has pros and cons. It makes your models slightly coupled to Spring MVC but allows you to return different views if say you had to redirect on some inputs (
RedirectView
).- Returns:
- the model that will be used as View
- See Also:
- API Note
- Notice that the return type is
View
.
-
wired
Here we use the wired renderer that does not have filtering and thus cannot use JMustache for dynamic editing of templates.- Parameters:
writer
- spring will inject the servlet output- Throws:
IOException
- an error while writing to the output
-