madhairsilence
madhairsilence

Reputation: 3880

Spring MVC Rest URL and URL redirection

Am developing an app using SpringMVC. In that app, I have a list of crud screens(almost 20 screens).

Now, I designed my controller in the following pattern of request mapping

Here , the problem is, I would like to expose this URL as both REST Service as Well as Normal Spring controller(directs to a new page after CRUD operations).

ie. When I use the application, it should do the CRUD operation and redirect to specific pages(Accordingly)

When I call as a rest service (using REST Clients). I should get the JSON data

Is it possible??

Upvotes: 0

Views: 904

Answers (3)

hoserdude
hoserdude

Reputation: 829

I would cleanly separate your AJAX/JSON calls from your page navigation. In other words, assign responsibility for the page navigation to one controller (or leverage an SPA routing mechanism on the client side), and the data access to another "service" controller. You then have a reusable and testable service and an independent navigation flow (which could evolve, change technologies etc).

Upvotes: 1

Jens Schauder
Jens Schauder

Reputation: 81998

I think what you are looking for is content negotiation. Google recommends this article: http://blog.springsource.org/2013/05/11/content-negotiation-using-spring-mvc/

Upvotes: 0

Naresh J
Naresh J

Reputation: 2137

As far as know, I don't think so. But one way will be like, each time your controller will produce JSON response. But for web application you need to add extra call for each request which will load desired page and then call your CRUD methods on load of your page and parse the JSON response to fill the data.

Upvotes: 0

Related Questions