Spring, the average score in the request parameter

Is there a way to map the query parameter to the average score using queries in spring?

I have no problems with binding to single-partition parameters:

Uri example: http://localhost:8080/test/?product=hotels

public class CitiesRequest{
    private ProductType product;

    public ProductType getProduct() {
        return this.product;
    }

    public void setProduct(String product) {
        this.product = product;
    }
}

But I would like to receive such parameters:

http://localhost:8080/test/?product-type=hotels
+1
source share
2 answers

By default, Spring maps the request parameter key to the name of the Java variable. However, it is syntactically incorrect to have a variable name with a hyphen in Java, which explains why it is especially difficult for you to get Spring to set the parameter value for you.

, , - Map<String, String[]> all. Spring , . , , .

WebDataBinder, , HTTP- . , Spring. " ".

+2

, Java. Spring ( ), ( Java-). , RequestMapping :

@RequestMapping("/test")
public ModelAndView getProduct(
        @RequestParam("product-type") String productType) {
...
}

, getProduct url http://localhost/test?product-type=hotels, productType hotels. .

+5

Source: https://habr.com/ru/post/1726314/


All Articles