0

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

  • create
  • show
  • update
  • delete

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??

1
  • Are you implying that in one case you return HTML and in the other case you return JSON and the first is less RESTy then the later? If so, I think you misunderstood something. If not obviously I misunderstood something. Commented Jul 12, 2013 at 6:01

3 Answers 3

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.