Search code examples
javajsonspringthymeleaf

Java Spring - Servicing Thymeleaf URI's and JSON


I want make a db/gateway solution using Spring with Hibernate. In addition to mobile clients, I also want to service a web portal that uses Thymeleafs. Thus, for serving the web portal, I want to implement Controllers that return Thymeleaf URI's. Can I do this but also serve JSON to mobile clients?


Solution

  • Considering the fact that you want to send data to mobile clients using JSON, it would seem more appropriate that you create an additional controller that handles another set of URIs, that are related to requests sent by the mobile clients. In other words, you should create a Web API for your application. JSON implies RESTful service, so the controller you are going to create will have the @RestController annotation on top of the controller class declaration, instead of @Controller.

    In case you haven't been there yet, visit the following Spring tutorial and guide.