Issue
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.
Solution
As stated in the comments, you should use @ResponseBody
annotation on your method.
That's all you need.
Answered By - Mahozad
Answer Checked By - Katrina (JavaFixing Volunteer)