request-mapping

How @RequestMapping internally works in Spring Boot?

戏子无情 提交于 2019-12-12 14:47:45
问题 @RestController @RequestMapping("/employee") public class Employee { @RequestMapping("/save") public void saveEmployee() { // saving employee } } How does @RequestMapping will work internally to map the request to the saveEmployee method? 回答1: During application startup, Spring will identify all Bean s by way of XML Config, Java Config, or Component Scanning and store them in the ApplicationContext . Spring Boot autoconfigures many Beans for you, including RequestMappingHandlerMapping. When

Handling ambiguous handler methods mapped in REST application with Spring

空扰寡人 提交于 2019-12-12 07:54:29
问题 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':

Adding PathVariable changes view path on RequestMapping

五迷三道 提交于 2019-12-11 12:46:47
问题 I have a view resolver: @Bean public InternalResourceViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("WEB-INF/jsp/"); resolver.setSuffix(".jsp"); return resolver; } and a controller: @Controller public class WorkflowListController { @RequestMapping(path = "/workflowlist", method = RequestMethod.GET) public ModelAndView index() throws LoginFailureException, PacketException, NetworkException { String profile = "dev";

Spring controller: How to use property ${..} in @RequestMapping?

坚强是说给别人听的谎言 提交于 2019-12-11 04:13:11
问题 I already found questions with answers but they don't help me. I have a web servlet project where I use a Spring Controller (4.2.5) and Spring Security (4.0.2). I don't use Spring Boot. My project works fine. But now my task is this: Make @RequestMapping(value={"auth/**"} configurable (replace "auth/**" with ${dm.filterPattern} ) Problem: in @RequestMapping ${dm.filterPattern} isn't resolved, although @PropertySource is processed. This is the entry dm.filterPattern in dmConfig.properties: dm

Spring MVC 3: same @RequestMapping in different controllers, with centralised XML URL mapping (hybrid xml/annotations approach)

拜拜、爱过 提交于 2019-12-10 15:53:32
问题 I like to keep all my mapping in the same place, so I use XML config: <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /video/**=videoControllerr /blog/**=blogController </value> </property> <property name="alwaysUseFullPath"> <value>true</value> </property> </bean> If I create a second request mapping with the same name in a different controller, @Controller public class BlogController { @RequestMapping(value = "/info", method

Meaning of “params” in @RequestMapping annotation?

谁都会走 提交于 2019-12-10 03:52:12
问题 I am aware of @RequestMapping annotation which is used in Spring MVC based application. I came across this piece of code: @RequestMapping(method = POST, params = {"someParam"}) I understood the method . However I don't know what params means? Before this I never had seen anything which passed params to this annotation. Can anyone help in understanding this? 回答1: Your example means that the parameter someParam must be present in the request. This is used to narrow down the matching methods for

Spring controller request mapping issue for dot in resource

我怕爱的太早我们不能终老 提交于 2019-12-09 22:27:01
问题 I am using spring 3.2.2 jars and have a controller with mapping "/validate". If i invoke "/validate.123" in browser url, this mapping method get executed which shouldn't be. Is't a problem in my code or spring issue? @Controller @SessionAttributes public class ValidationController { @RequestMapping(value = "/validate", method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView validatCheck(@ModelAttribute("po") PO po){ } web.xml <web-app xmlns="http://java.sun.com/xml/ns/javaee"

How do I make @Controller mapping path configurable?

自闭症网瘾萝莉.ら 提交于 2019-12-07 02:22:55
问题 I'm building an internal library that should automatically add a few controllers to Spring MVC application. These controllers are all @RestController with a few handler methods annotated with @RequestMapping . Since it's a library, I want users to be able to specify the root path where the library should expose all these controllers. Illustration: // given that I have a controller like this: @RestController @RequestMapping("/admin") class AdminController { @RequestMapping("/users") UsersDto

Using Spring's @RequestMapping with wildcards

血红的双手。 提交于 2019-12-06 21:28:19
问题 This is similar to this question, but I am still confused about my situation. I want to map this ant-style pattern to a controller method: /results/** That is, I want any URL like www.hostname.com/MyServlet/results/123/abc/456/def/ to go to this method. I have: <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/results/*</url-pattern> </servlet-mapping> and: @RequestMapping(value="/**", method=RequestMethod.GET) public ModelAndView handleRequest() {...} This works to guide

Spring controller request mapping issue for dot in resource

本秂侑毒 提交于 2019-12-04 15:46:55
I am using spring 3.2.2 jars and have a controller with mapping "/validate". If i invoke "/validate.123" in browser url, this mapping method get executed which shouldn't be. Is't a problem in my code or spring issue? @Controller @SessionAttributes public class ValidationController { @RequestMapping(value = "/validate", method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView validatCheck(@ModelAttribute("po") PO po){ } web.xml <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun