How to pass two list as @RequestBody in Spring boot controller

107 views Asked by At

I am using two list in my html and send as json object

var data=[];
   for(i=1;i<=cnt;i++){
    var tabledata={
        indent_kid : $(document.getElementById("indent_sch_List[" + i + "].indent_kid")).val(),
        indent_schduled_qty : $(document.getElementById("indent_sch_List[" + i + "].indent_schduled_qty")).val(),
        indent_allocated_qty : $(document.getElementById("indent_sch_List[" + i + "].indent_schduled_qty")).val(),
        indent_supplier : $(document.getElementById("indent_sch_List[" + i + "].indent_supplier")).val(),
        indent_transporter : $(document.getElementById("indent_sch_List[" + i + "].indent_transporter")).val(),
        indent_deliveryp : $(document.getElementById("indent_sch_List[" + i + "].indent_deliveryp")).val()
        //alert(indentkid+","+indent_schduled_qty+","+indent_allocated_qty+","+indent_supplier+","+indent_transporter+","+indent_deliveryPoint);
    }
    data.push(tabledata);
    }
    
     var datas=[];
   for(s=1;s<=scnt;s++){
    var tabledatas={
        indent_supplier : $(document.getElementById("indent_sup[" + s + "].indent_supplier")).val(),
        indent_schduled_qty : $(document.getElementById("indent_sup[" + s + "].indent_schduled_qty")).val(),
        
        //alert(indentkid+","+indent_schduled_qty+","+indent_allocated_qty+","+indent_supplier+","+indent_transporter+","+indent_deliveryPoint);
    }
    datas.push(tabledatas);
    }
    
    
    // Convert data array to JSON
    var jsonData = JSON.stringify(data);
    var jsonDatas = JSON.stringify(datas);
        console.log(jsonData);
        fetch('[[@{/indentScheudleSave}]]', {
        method: 'POST',
        headers: {
        'Content-Type': 'application/json'
      },
      body: jsonData,jsonDatas
    })

my controller code is

@PostMapping({"/indentScheudleSave"})
    public ModelAndView scheduleIndentSave(HttpSession session,Model model, EmpBean emp,@RequestBody List<IndentScheduleBean> dataList,  List<ContractMasterBean> dataLists ){
        System.out.println("Saving of Schedule");
        String sv = (String)session.getAttribute("emp_no");
        
        dataList.forEach(System.out::println);
        //System.out.println(transporter+" "+supplier+" "+deliveryPoint+" "+indent_date+" "+allocated_qty);
        for(IndentScheduleBean s:dataList) {
        System.out.println("Json List "+s.getIndent_kid() + "," +s.getIndent_allocated_qty());}
        
        for(ContractMasterBean s:dataLists) {
            System.out.println("Json List Schedulaer"+s.getIndent_supplier() + "," +s.getIndent_schduled_qty());}
}

The above code is working fine when i am using single list in @RequestBody List<IndentScheduleBean> dataList but when i am using above two list it is giving below error

ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] -Servlet.service() for servlet [dispatcherServlet] in context with path [/ngportal] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or single unique constructor found for interface java.util.List] with root cause
0

There are 0 answers