Use result style development

After the form is submitted, the control layer will call different methods according to the form submission

1. GET submitted

 

 

@RequestMapping ( value = "uid {}" , Method = RequestMethod.GET) // the GET: Query 
    public String the findById ( @PathVariable ( "uid")  int id) { // @PathVariable the value assigned to the parameter id uid 
        System.out.println ( "the findById ================" + ID);
         return "index" ; 
    }

2. POST submission

 

 

@RequestMapping (Method = RequestMethod.POST) // the POST: Add 
    public String insertuser ( the Users user ) {// Get the page end user object coming 
        System.out.println (user + "add" );
         return "index" ; 
    }

3. PUT and DELETE submitted         using PUT and DELETE submission need to add a filter in the configuration file web.xml

  3.1 PUT submitted

<! -  
        the post request into PUT and DELETE requests 
        using _method represent real submission
      -> 
    <filter> 
        <filter-name> hiddenHttpMethodFilter </ filter-name> 
        <filter- class > org.springframework.web. filter.HiddenHttpMethodFilter </ filter- class > 
    </ filter> 
    <filter-Mapping> 
        <filter-name> hiddenHttpMethodFilter </ filter-name> 
        <URL-pattern> / * </ URL-pattern> 
    </ filter-Mapping>

 

   Background code

@ RequestMapping (= Method, RequestMethod.PUT) // PUT: Updates 
    @ResponseBody // The java json object into an object, if it does not add the comment page will report a 405 error 
    public String Update (the Users the User) { 
        System.out.println ( User + "update" );        
         return "index" ; 
    }

  3.2 DELETE submitted

 

 

@ RequestMapping (value = "{uid}", Method, = RequestMethod.DELETE) // DELETE: Delete 
    @ResponseBody // The java json object into an object, if it does not add the comment page will report a 405 error 
    public String the Delete (@PathVariable ( "UID") int ID) { 
        System.out.println ( "Delete ======" + ID);
         return "index" ; 
    }

 

 

Guess you like

Origin www.cnblogs.com/mcl2238973568/p/11470091.html