views:

30

answers:

1

psuedo:

@RequestMapping("/news/feed/featurednews/{feedname}")
public List<NewsModel> getFeed(String feedname, @RequestParam("start", optional) Integer startIndex) {
   return feedService.getFeaturedNewsByName(feedname);
}

@RequestMapping("/news/{newsPageName}")
public String goToNewsPage(Model m, String newsPageName) {
   m.addAttribute("stories", feedService.getFeaturedNewsByName(newsPageName));
   return getGenericNewsViewName();
}

as you can see I'm reusing the service that gets the feed, is that the best I can do here, or can I reuse the getFeed() method?

+3  A: 

It's perfectly fine to write

@RequestMapping("/news/feed/featurednews/{feedname}")
public List<NewsModel> getFeed(String feedname, @RequestParam("start", optional) Integer startIndex) {
   return feedService.getFeaturedNewsByName(feedname);
}

@RequestMapping("/news/{newsPageName}")
public String goToNewsPage(Model m, String newsPageName) {
   m.addAttribute("stories", this.getFeed(newsPageName, 0));
   return getGenericNewsViewName();
}

The Controller by itself is a plain Java class, you just tell the Spring request dispatcher on where to map requests to using the annotations (which doesn't affect any normal method call).

Daff
That's great, I don't know why I didn't think this would be something reasonable to do, I guess I was figuring that there may be some special request processing that would screw it up, hail spring 3!
walnutmon