Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable Thymeleaf, or only enable for certain REST calls?

Tags:

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.

like image 608
user2494663 Avatar asked Aug 22 '17 19:08

user2494663


People also ask

How do I disable Thymeleaf?

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.

Do people still use Thymeleaf?

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.

Is Thymeleaf fully integrated with Spring?

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.


1 Answers

As stated in the comments, you should use @ResponseBody annotation on your method.
That's all you need.

like image 165
Mahozad Avatar answered Oct 11 '22 10:10

Mahozad