No primary or single public constructor found for interface java.util.List - and no default construc

SpringBoot receives a parameter of type List and reports an error

  • Problem background :

    When writing St. Regis takeout, I want to delete in batches and use List to receive the ids of the selected records, but after clicking the delete button, the backend reports directly, and the backend does not receive the parameters from the frontend at all
    No primary or single public constructor found for interface java.util.List - and no default construc.

  • problem causes

    For object-type data, especially request header parameters, you need to use the @Request annotation for mapping, otherwise SpringMVC does not know how to convert

  • solution

    • Solution 1 : Instead of using List ids to receive, use Long[] ids to receive
    • Solution 2@Request : Add annotations before List ids to tell SpringMVC to convert the request header parameters passed from the front end into the form of a List collection
      insert image description here

    PS: I used the second solution and successfully solved the problem O(∩_∩)O. If you think it is helpful to you, please give me a thumbs up

Guess you like

Origin blog.csdn.net/qq_66345100/article/details/130267198