How can I rewrite url in SpringMVC with tuckey's UrlRewriteFilter like this:
From
http://localhost:8080/demo/api.do?method=getUser&uid=1001
to
http://localhost:8080/demo/api/user/1001
The controller snippets:
@Controller
@RequestMapping("/api.do")
public class APIController {
@RequestMapping(params = "method=getUser")
public String methodName(HttpServletRequest request) {
//CODE BLOCK
}
}
Add a dependency if you're using maven
Enable the filter in your web.xml
Add the following rule to WEB-INF/urlrewrite.xml
Do you really need use URL rewrite filer? Why not define two methods for both types of URL and route to single method to handle processing
In SpringMVC, you can do it simply
@ResponseBody
if you send only object valuesalso you can send
user_id
as paramImportant thing you have add
Bean
for view resolver, here is annotation based example