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:

 

Recommended Today

Detailed explanation of spring cloud ribbon load balancing Shenkeng that cannot be connected through the server name

First, the problem. Take the Eureka cluster and the client calls the service through the ribbon. The ribbon side reports the following exceptions java.net.UnknownHostException: SERVICE-HI java.lang.IllegalStateException: No instances available for SERVICE-HI java.lang.IllegalStateException: Request URI does not contain a valid hostname: http://SERVICE-HI com.netfix.discovery.shared.taransport.TransportException: Cannot execute request on any known server The spring cloud version is messy, […]