I am new to Spring MVC & going through Craig Walls Spring4 in Action.
Consider the snippet,
@RequestMapping(value = "/spittles", method = RequestMethod.GET)
public String spittles(Model model, @RequestParam("max") long max,
@RequestParam("count") int count) {
model.addAttribute("spittleList",spittleRepository.findSpittles(max, count));
return "spittles"; // <-- return view name
}
The image shows the spittles.jsp resides in /WEB-INF/views/
WebConfig.java:
@Configuration
@EnableWebMvc // Enable Spring MVC
@ComponentScan(basePackages={"org.spittr"})
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver =
new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
/* configure static content handling */
configurer.enable();
}
}
1) Why do I need to return the string "spittles" in the controller method?
2) Does it(return string) holds a relationship to the
@RequestMapping(value = "/spittles", method = RequestMethod.GET)
as the value(/spittles) is the same as the returned string in the controller method?
3) Why don't I see a .jsp extension when i enter the URL
http://localhost:8080/web/spittles?max=238900&count=5
and the o/p is resolved as: