Ajax Request - calling another method in a Spring controller

I am having a problem using AJAX with Spring MVC. I have a form that has many fields, and each field retrieves data depending on the corresponding button that was clicked.

So, each of my buttons should trigger an AJAX request. Each answer will be displayed in the corresponding field.

I wonder if it is possible to call another method in my Spring controller as soon as I clicked on another button?

In other words, I want to make several ajax requests to one controller, where each request will call a different method in the same controller.

See this example:

    // when get account detail is clicked it will call this method  
@RequestMapping(method=RequestMethod.POST)  
    public @ResponseBody String getAccountDetails(@RequestParam(value="accountid") String accountid){  

     return somefunct.getAccountDetails(accountid);  

    }  



// when get account summary is clicked it will call this method  
@RequestMapping(method=RequestMethod.POST)  
    public @ResponseBody String getAccountSummary(@RequestParam(value="accountid") String accountid){  

      return somefunct.getAccountSummary(accountid);  

    }  



/* when submit button is clicked... Form is submitted for saving*/  
@RequestMapping(method=RequestMethod.POST)  
    public String submitForm(){  
        // save here  
        return "myform";  
    };*/  

Currently, I can only have one AJAX request. How can I change this code to have different functions for different AJAX requests?

+5
1

, HTTP GET, POST. , HTTP-.

-, URL , value RequestMapping.

-, RESTful PathVariable :

@RequestMapping(value="/account/{accountid}/details", method = RequestMethod.GET)
public @ResponseBody String getAccountDetails(@PathVariable(value="accountid") String accountid){  

 return somefunct.getAccountDetails(accountid);  

}  

URL-, URL- , " " :

// when get account summary is clicked it will call this method  
@RequestMapping(value="/account/{accountid}/summary", method=RequestMethod.GET)  
public @ResponseBody String getAccountSummary(@PathVariable(value="accountid") String accountid){  

    return somefunct.getAccountSummary(accountid);  

}  

, , . , , GET, , , . HTTP-, , - HTTP POST. HTTP PUT .

PUT POST , PUT , , , . , POST.

, URL-. , . , POST. , PathVariable, URL, RequestBody, , Java:

/* when submit button is clicked... Form is submitted for saving*/  
@RequestMapping(value="/account/{accountid}", method=RequestMethod.POST)  
    public String submitForm(@PathVariable String accountid, @RequestBody Account account){  
        // save here  
        return "myform";  
}

Spring MVC Spring Spring MVC.

+8

All Articles