0

These are the String-type parameters I want to send.
I have to send two parameters to DB and use them to query data, and get the data back as JSON array type.
I also got jackson-databind library in my project.

  var startDate = picker.startDate.format('YY-MM-DD');
  var endDate = picker.endDate.format('YY-MM-DD');

  var dates = { "startDate": startDate, "endDate": endDate };   


This is the Ajax code

        $.ajax({
            url: "selectCouponByTerm",
            type : "POST",
            data : dates,
            contentType : "application/json; charset=utf-8",
            success : function(data){
                dataTable.attr('data', JSON.stringify(data)).trigger("create");
                console.log(data);
            },
            error : function(e){
                console.log(e.status);
            }
        })

Then in the controller,

  @PostMapping("/selectCouponByTerm")
  @ResponseBody
  public List<Coupon> selectCouponByTerm(@RequestBody String startDate,
                                         @RequestBody String endDate) {
      return "adminService.selectCouponByTerm(startDate, endDate)";
  }

it gives me Type mismatch: cannot convert from String to List<Coupon> error.

1 Answer 1

1

Remove the enclosing double quotes from the return statement

Sign up to request clarification or add additional context in comments.

3 Comments

Now it shows adminService cannot be resolved. The controller can't recognize the service interface.
adminService is a reference of the service object, you need to autowire it in controller, if you are new for the backend coding, I would suggest to check how other controllers are organised in your codebase, or check some online tutorials.
I forgot to autowired the service. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.