Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Intro to Java Web Development with Spark Bells and Whistles Adding to and Iterating a List

Sergei Makarov
Sergei Makarov
13,839 Points

MVC Pattern. Who is who in Spark?

So, please correct me, if I am not right.

Model - "[..] stores data, that is retrieved according to commands from the controller and displayed in the view."

View - "[..] generates an output presentation to the user based on changes in the model."

Controller - "[..] can send commands to the model to update the model's state (can also be associated to change the view's presentation of the model)."

I believe, i could associate it follows:

Model is concatenated with View through ModelAndView.class; Model we can present as Java Collections Framework (e.g. Map);

View is all that will be parsed of HandlebarsTemplateEngine.class (I mean in this case, as I reference to this very course (html, css ans so on);

What is then a Controller? JavaScript? REST API? Both?

Thank you for your answers.

1 Answer

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Sergei Makarov , great question!!

Yeah in our situation the "routes" the lambda that starts with(req, res) is our controller. It is responsible for controlling the flow and filling out the model (any object) which is used to push into our view (our html, currently rendered by HandleBars, but could be anything).

That help clear things up?

Sergei Makarov
Sergei Makarov
13,839 Points

Yep. Thank you for your answer, Craig!

You have mentioned also a Spring Basics course to my previous question. Good to know. Go there after this!