How should I handle URL routing in my application?

I am building a web application with custom components. I need a way to route requests to a class / methods, is there a separate java library that can achieve this (in a sexy way [1])?

[1] read: no xml!

+4
source share
2 answers

In Spring WebMVC 2.5 / 3, you can do all this with annotations. The obvious drawback is that, of course, the annotation values ​​must be a compile-time constant, so you can get some effectively hard-coded URLs. If you go all-in with auto-preparation, basically the only XML is a couple of lines for creating a servlet, enabling scanning with autowiring + package, and possibly defining a resolution strategy for the view.

eg.

@Controller public class WebController { @RequestMapping(value="/pages/Home.htm", method=RequestMethod.GET) public ModelMap buildHome(@RequestParam("foo", required=false) String foo){ return fillInHomePageData(foo); } 

In a degenerate resolution strategy, it can, for example, automatically go to the jsp / pages / Home.jsp search and build it with the data you returned.

+1
source

You can take a look at Reflection , it is quite sexy and does not require XML. What can he do so that he runs classes for input-based routing.

0
source

Source: https://habr.com/ru/post/1308637/


All Articles