Spring MVC support for RESTful

Time:2019-10-7

1: Background Controller Method

@RequestMapping("/itemsLook/{id}")
 public ItemsCustom itemsLook(@PathVariable("id")Integer itemsId) throws MyException {
   ItemsCustom itemsCustom = this.itemsService.getItems(itemsId);        
   return itemsCustom;
 }
 /*
 @ PathVariable: Binding (mapping) the values of template variables (parameters) to parameters
 
 @PathVariable
 1: If no name is specified
 The name of the template variable (parameter) {id} must be the same as the name of the formal parameter Integer ID.
 
 2: If the name is specified
 Template variable (parameter) {id} must have the same name as @PathVariable ("id").
 The name of the template variable (parameter) {id} need not be the same as the name of the formal parameter Integer itemsId.
 */

2: Dispatcher Servlet configuration supporting RESTful style

Add the following configuration to web.xml:

springMVCRESTful
     org.springframework.web.servlet.DispatcherServlet
     
       contextConfigLocation
       classpath:springMVC.xml
     
   
   
     springMVCRESTful
     /

3: Conduct RESTful testing

4: Static resource allocation

Because <servlet-mapping>Configured in<url-pattern>Yes/, which will result in inaccessibility of static resources. The solution is as follows:

Add the following configuration to spring MVC.xml: