@Controller
public class HotelsController
{
privateTravelServicetravelService;
@Autowired
publicHotelsController(TravelServicetravelService) {
this.travelService = travelService;
}
@RequestMapping("/hotels")
public void getHotels(SearchCriteria criteria, Model model) {
List<Hotel> hotels = travelService.findHotels(criteria);
model.addAttribute(“hotelList”, hotels);
}
}
This
Java bean is annotated to inform Spring to bind to the incoming URL of /hotels.
When the Spring MVC dispatcher servlet must identify the controller that can
handle the incoming URL, it consults these annotations to find your bean. As you
can see by the code, all the “heavy lifting” is done inside the bean. It calls
out to the travelService to retrieve a list of hotel properties, places these
into the model, and then returns it. In this example, you are populating the
model in the controller. So far, this is all Spring Web MVC.