0

I am having a scope Object in Angular Controller.

When I try to pass it onto Spring Rest Controller , the control is passed to Spring rest controller. But when I try to print the value its getting printed as null.

Scenario:

AngularController :

file.upload = Upload.upload({
    url : '/uploadTemplate',
    data : {
        multipartFile : file,
        am : appMaster
    }
});

RestController.java

@RequestMapping(value = "/uploadTemplate", produces = "application/json")
@ResponseBody
public StringResponse uploadFiles(MultipartFile multipartFile,ApplicationMaster am) {
        System.out.println("Inside");

        System.out.println(am.getAbbreviation());
        System.out.println(am.getAppId());
        System.out.println(am.getName());
}

The first System.out.println Inside is getting printed in console , but next the values of am object are printed as null.

If I alert the values in AngularController , the desired values are alerted.

7
  • First of all you should send a multipart request to the server not a regular request. second you need a @RequestBody on the ApplicationMaster object to unmarshall the request body. Commented Sep 20, 2017 at 13:27
  • I tried with it, but still the same issue. If i give RequestBody on the ApplicationMaster object, the control doesnt come to restcontroller. i.e , None of the System.out.println statements are executed. Commented Sep 20, 2017 at 13:45
  • Well no it won't because, as stated, you should be sending a multipart request. You are sending JSON with 2 attributes which will be marshaled onto the ApplicationMaster. I strongly suggest a read of the spring reference guide and how (un)marshaling JSON works. Commented Sep 20, 2017 at 13:46
  • Is there any other alternative? Any pointers on ** how to send multipart request ** will also be helpfull. Thanks : ) Commented Sep 20, 2017 at 14:30
  • @M.Deinum , Any other alternative? Is there any way to convert scope object , so as to get values mapped to rest controller? Help me out!! Thanks Commented Sep 21, 2017 at 8:51

0

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.