In my spring boot application a request comes from the client with the following URL. localhost:8080/api/invoice?invoiceNo=1234&invoiceDate=050218&invoiceNo=6543&invoiceDate=060218
How can I get the values for the request property invoiceNo and invoiceDate. I know we can always use some delimiter while building the URL and fetch it. I would like to know if there is any springboot way for achieving this. Any help is much appreciated. Now when I try request.getParameter("invoiceNo")
I get only the first parameter.
使用清单
public void invoice(@RequestParam(name="invoiceNo") List<String> invoiceNos, @RequestParam(name="invoiceDate") List<String> invoiceDates) {
As @maruthi mentioned request.getParameterValues("invoiceNumber")
is one way. Another way is to add @RequestParam(value="invoiceNo", required=false) List<String> invoiceNo
as the controller method parameter.
In spring you can get query parameters by using the annotation @RequestParam
inside controller's endpoint method like this:
@GetMapping("/invoice")
public CustomResponse getInvoiceData(
@RequestParam(value="invoiceNo") List<Long> invoiceNoList,
@RequestParam(value="invoiceDate", required = false) List<Date> invoiceDateList){
...
}
You can see another values that this annotation can get (like required, default, etc..) in the docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.