For instance, I have a basic POST that returns an html called "result" using Thymeleaf. This works and is cool.
@PostMapping("/greeting")
public String greetingSubmit(@ModelAttribute Greeting greeting) {
return "result";
}
But I have another totally unrelated method, that does something different, and returns not a template.
@PostMapping(value = "/otherstuff", headers = "content-type=multipart/*")
public Object otherStuff(@RequestParam("file") MultipartFile dataFile) {
// Totally unrelated stuff
return resultList;
}
Naturally, I get an exception:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/otherstuff", template might not exist or might not be accessible by any of the configured Template Resolvers
because I'm intentionally not resolving a template. Can I turn off ThymeLeaf for this method? My Rest API is multi-purpose, and it would be rather unhelpful if ThymeLeaf ends up disrupting the whole project.
Thanks.
Make use of ThymeLeaf tag with single HTML representation The second and preferred way is to set th:disabled on drop down control. The value of disabled is set through model attribute isEnabled. You can set this model attribute on controller and you will be good to go for active or disabled drop downs.
While Thymeleaf is more of a template engine for server-side application development. But Thymeleaf's popularity is on a steady rise. The developer community is slowly moving away from 'once a common' MVC framework for Javascript-based development.
It provides full integration with Spring Framework. It applies a set of transformations to template files in order to display data or text produced by the application. It is appropriate for serving XHTML/HTML5 in web applications. The goal of Thymeleaf is to provide a stylish and well-formed way of creating templates.
As stated in the comments, you should use @ResponseBody
annotation on your method.
That's all you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With