request-mapping

Spring MVC referencing params variable from RequestMapping

心不动则不痛 提交于 2019-11-29 00:09:16
问题 I have the method below: @RequestMapping(value = "/path/to/{iconId}", params="size={iconSize}", method = RequestMethod.GET) public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws IOException { // Implementation here } I know how to pass the variable "webletId" from the RequestMapping using the @PathVariable, but how do I reference the variable "iconSize" from params? Thanks a lot. 回答1: Use @RequestParam : @RequestMapping

Custom Spring annotation for request parameters

南楼画角 提交于 2019-11-28 17:13:21
问题 I would like to write custom annotations, that would modify Spring request or path parameters according to annotations. For example instead of this code: @RequestMapping(method = RequestMethod.GET) public String test(@RequestParam("title") String text) { text = text.toUpperCase(); System.out.println(text); return "form"; } I could make annotation @UpperCase : @RequestMapping(method = RequestMethod.GET) public String test(@RequestParam("title") @UpperCase String text) { System.out.println(text

Combine GET and POST request methods in Spring

﹥>﹥吖頭↗ 提交于 2019-11-28 04:49:08
I have a resource that supports both GET and POST requests. Here a sample code for a sample resource: @RequestMapping(value = "/books", method = RequestMethod.GET) public ModelAndView listBooks(@ModelAttribute("booksFilter") BooksFilter filter, two @RequestParam parameters, HttpServletRequest request) throws ParseException { LONG CODE } @RequestMapping(value = "/books", method = RequestMethod.POST) public ModelAndView listBooksPOST(@ModelAttribute("booksFilter") BooksFilter filter, BindingResult result) throws ParseException { SAME LONG CODE with a minor difference } The code in the two

Spring mvc Ambiguous mapping found. Cannot map controller bean method

徘徊边缘 提交于 2019-11-27 15:32:52
问题 I am trying to build an app which can list some values from the database and modify, add, delete if necessary using Spring 4 and i receive the following error(only if the "@Controller" annotation is present in both of my controller files, if i delete the annotation from one of the files it works but i get a message in console "no mapping found ... in dispatcherservlet with name ...): INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/edit/

Multiple Spring @RequestMapping annotations

风格不统一 提交于 2019-11-27 02:36:35
Is it possible to use multiple @RequestMapping spring annotations in a method? Like: @RequestMapping("/") @RequestMapping("") @RequestMapping("/welcome") public String welcomeHandler(){ return("welcome"); } @RequestMapping has a String[] value parameter, so you should be able to specify multiple values like this: @RequestMapping(value={"", "/", "welcome"}) Alan Zhong From my test (spring 3.0.5), @RequestMapping(value={"", "/"}) - only "/" works, "" does not. However I found out this works: @RequestMapping(value={"/", " * "}) , the " * " matches anything, so it will be the default handler in

Combine GET and POST request methods in Spring

混江龙づ霸主 提交于 2019-11-27 00:31:40
问题 I have a resource that supports both GET and POST requests. Here a sample code for a sample resource: @RequestMapping(value = "/books", method = RequestMethod.GET) public ModelAndView listBooks(@ModelAttribute("booksFilter") BooksFilter filter, two @RequestParam parameters, HttpServletRequest request) throws ParseException { LONG CODE } @RequestMapping(value = "/books", method = RequestMethod.POST) public ModelAndView listBooksPOST(@ModelAttribute("booksFilter") BooksFilter filter,

Spring 3 MVC accessing HttpRequest from controller

人走茶凉 提交于 2019-11-26 12:58:36
I would like to handle request and session attributes myself rather then leave it to spring @SessionAttributes , for login of cookies handling for example. I just cant figure out how could I access the HttpRequest from within a controller, I need a way to go a layer above the @RequestAttribute and access the HttpRequest itself. With Stripes in used to do this by implementing an ApplicationContext and calling getAttribute() . Also, passing the HttpServletRequest as parameter seems not to be working: @RequestMapping(value="/") public String home(HttpServletRequest request){ System.out.println(""

Multiple Spring @RequestMapping annotations

北战南征 提交于 2019-11-26 12:34:50
问题 Is it possible to use multiple @RequestMapping spring annotations in a method? Like: @RequestMapping(\"/\") @RequestMapping(\"\") @RequestMapping(\"/welcome\") public String welcomeHandler(){ return(\"welcome\"); } 回答1: @RequestMapping has a String[] value parameter, so you should be able to specify multiple values like this: @RequestMapping(value={"", "/", "welcome"}) 回答2: From my test (spring 3.0.5), @RequestMapping(value={"", "/"}) - only "/" works, "" does not. However I found out this

Spring 3 RequestMapping: Get path value

≡放荡痞女 提交于 2019-11-26 01:44:20
问题 Is there a way to get the complete path value after the requestMapping @PathVariable values have been parsed? That is: /{id}/{restOfTheUrl} should be able to parse /1/dir1/dir2/file.html into id=1 and restOfTheUrl=/dir1/dir2/file.html Any ideas would be appreciated. 回答1: Non-matched part of the URL is exposed as a request attribute named HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE : @RequestMapping("/{id}/**") public void foo(@PathVariable("id") int id, HttpServletRequest request) {