0

I am new to MVC and searched a lot about it and following are the things which i found on Stackoverflow. 1. With angularJS at client side ---> NodeJS , Rails are good to be used on server side as they have certain benifits.

Now i have a question :- even spring is an MVC framework, but can i use Servlet and Angular JS and implement MVC with it? Thanks in advance.

Shripad Ashtekar
  • 201
  • 3
  • 17

2 Answers2

1

Angular doesn't really care what you're using server side it just expects to be able to send JSON encoded data in the body of requests and get responses that are JSON encoded. So the short answer is yes you can. Regarding MVC there's basically layers of this design pattern used throughout the client side framework itself, on the server side typically I just have code that loads data from a database (or updates/inserts/deletes data) then encodes it and sends it to the client. This way the server is essentially decoupled from the client and either could be rewritten or appended/supplemented without replacing either.

MVC just means model view controller, which is a design pattern for dividing up code. The model is the data itself and is "the source of truth" for updating the view, the controller is responsible for making changes to the model, and the current state of the model is always reflected in the view.

With Spring MVC traditionally the server would be responsible for wholly processing the request using a controller that updates the model then generating a view that was delivered to the client.

With Angular you use AJAX requests to get data from the server, then you update your model (typically through a controller as a proxy to a service/factory in angular terms) and then the bindings/watches in angular automatically update the view.

So in the case of angular really your server side is not responsible for creating the view but only responsible for persisting data (and dealing with authentication and authorization). On your server side you may still maintain a model that corresponds to some schema in a database or otherwise and you may have some route handling layer that you could consider the server side controller that acts on the model, you're just not really dealing with the view at all anymore.

There are lots of advantages to this approach both for the end user and in terms of development. You can test your backend and frontend separately and you can refactor or replace either or build additional frontends (native clients etc.) or add backend modules without disturbing the clients. The only thing you need to take care of is maintaining a consistent interface between your client and server components.

shaunhusain
  • 19,630
  • 4
  • 38
  • 51
1

In short, Yes.

Just make sure you are passing the data in JSON format because AngularJS expects JSON, as explained by @shaunhusain.

This link will be very much helpful to understand how to create folder structure for the application.

Community
  • 1
  • 1
Ashyboy
  • 163
  • 1
  • 8