request-mapping

Handling ambiguous handler methods mapped in REST application with Spring

岁酱吖の 提交于 2019-12-03 14:30:42
I tried to use some code as below: @RequestMapping(value = "/{id}", method = RequestMethod.GET) public Brand getBrand(@PathVariable Integer id) { return brandService.getOne(id); } @RequestMapping(value = "/{name}", method = RequestMethod.GET) public List<Brand> getBrand(@PathVariable String name) { return brandService.getSome(name); } But I got error like this, how can I do? java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/brand/1': {public java.util.List com.zangland.controller.BrandController.getBrand(java.lang.String), public com

Spring Boot not loading static resources it depends on RequestMapping depth

自作多情 提交于 2019-12-02 19:45:54
问题 I have problem to load the file under static folder on spring boot application. The problem is RequestMapping depth more than 2 like @RequestMapping("spring/xyz") The @RequestMapping("spring") single depth works well but 2 depth is prefixed 'spring' it is connect localhost:8080/spring/'static folder' I found half solution here my folder structure is: static/css/some.css static/templates/velocity.vm case 1: works well java: @RequestMapping("spring") html: <link rel="stylesheet" href="css/some

Spring Boot not loading static resources it depends on RequestMapping depth

≯℡__Kan透↙ 提交于 2019-12-02 08:23:39
I have problem to load the file under static folder on spring boot application. The problem is RequestMapping depth more than 2 like @RequestMapping("spring/xyz") The @RequestMapping("spring") single depth works well but 2 depth is prefixed 'spring' it is connect localhost:8080/spring/'static folder' I found half solution here my folder structure is: static/css/some.css static/templates/velocity.vm case 1: works well java: @RequestMapping("spring") html: <link rel="stylesheet" href="css/some.css"> case2: works well java: @RequestMapping("spring/xyz") html: <link rel="stylesheet" href="../css

Spring @RequestMapping “Not Contains” Regex

不羁的心 提交于 2019-12-02 07:02:52
I have this RequestMapping: @RequestMapping(value = "/route/to-{destination}-from-{departure}.html", method = {RequestMethod.GET, RequestMethod.HEAD}) And I would like to add that RequestMapping: @RequestMapping(value = "/route/to-{destination}.html", method = {RequestMethod.GET, RequestMethod.HEAD}) So it can serve all the "without departure" routes. That, however, creates a conflict as a "/route/to-destination-from-departure" url actually match this second RequestMapping as well... Fair enough so my solution was to specify a regex: @RequestMapping(value = "/route/to-{destination:^((?!-from-)

How to know which param of @RequestMapping is called

泄露秘密 提交于 2019-12-02 03:18:46
This is my @RequestMapping annotation: @RequestMapping({"/loginBadCredentials", "/loginUserDisabled", "/loginUserNumberExceeded"}) public String errorLogin(...){ ... } Inside the method errorLogin , is there a way to know which of the three url was "called"? Add HttpServletRequest as your parameters and use it to find the current request path. Update : Spring also provides RequestContextHolder : ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); String currentReqUri = attributes.getRequest().getRequestURI(); In my opinion, first

How to know which param of @RequestMapping is called

孤街醉人 提交于 2019-12-02 02:46:39
问题 This is my @RequestMapping annotation: @RequestMapping({"/loginBadCredentials", "/loginUserDisabled", "/loginUserNumberExceeded"}) public String errorLogin(...){ ... } Inside the method errorLogin , is there a way to know which of the three url was "called"? 回答1: Add HttpServletRequest as your parameters and use it to find the current request path. Update : Spring also provides RequestContextHolder : ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder

Spring MVC referencing params variable from RequestMapping

余生颓废 提交于 2019-11-30 03:04:07
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. Use @RequestParam : @RequestMapping(value = "/path/to/{iconId}", method = RequestMethod.GET) public void webletIconData(@PathVariable String iconId

Custom Spring annotation for request parameters

浪子不回头ぞ 提交于 2019-11-29 21:39:45
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); return "form"; } Is it possible and if it is, how could I do it ? Master Slave As the guys said in

Spring @RequestMapping

走远了吗. 提交于 2019-11-29 09:45:13
问题 I keep seeing this kind of param value = "/redirect/{id}" in a @RequestMapping annotation of the Spring. I keep wondering what is {id} here? Is this some sort of Expression Language ? Sample code of what I have seen: @RequestMapping( value = "/files/{id}", method = RequestMethod.GET ) public void getFile( @PathVariable( "id" ) String fileName, HttpServletResponse response ) { try { // get your file as InputStream InputStream is = new FileInputStream("/pathToFile/"+ fileName); // copy it to

Spring mvc Ambiguous mapping found. Cannot map controller bean method

一笑奈何 提交于 2019-11-29 02:53:26
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/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String