Adding The People By Location Controller

Now that we have the main landing page of the application created it is time to build our next page. To start the process of I have gone to VSTS and dragged the ‘See All Staff In A Single Location’ story over to the Active column.

I can now return to IntelliJ and start building my next controller. I’m going to add a new controller class to the application called LocationController. Don;t forget to annotate the called with the @Controller annotation so that Spring MVC will pick it up correctly.

The @RequestMapping annotation is set as /location/{id}. This part in the curly brackets is a dynamic mapping so that the request mapping will match a url like /location/PA or /location/NY etc. You can, in theory, match multiple parts of the incoming request so that something like /location/{state}/{city} would match a url of /location/pa/pittsburgh.

To extract the value that is being passed in on the dynamic RequestMapping you use the @PathVariable annotation in the methods signature.In this case I’m extracting ‘id’ from /location/{id}. if I was writing a signature to match the state/city example above I would write something like location(@PathVariable(“state”) String state, @PathVariable(“city”) String city, ModelMap model).

You will also notice I have autowired in the two repositories in my application and I’m adding all the locations in to the model just as I did with the main landing page (because the list of locations is displayed on all pages) and I have added a call to my personRepository that will return all the people in the specified location.

Next I’ll add this info to a html template called location.html

Tagged with: ,
Posted in Domino To Spring, None
%d bloggers like this: