0

I want to send object to Spring Controller with Angular JS and Restangular. That is how I try to do this:

var scoreTO = {
    score: parseFloat($scope.score.score),
    percentage: parseFloat($scope.score.percentage),
    date: (new Date()).getTime()
}
Restangular.one("scores").post(scoreTO);

There is transport object:

public class ScoreTO implements Serializable{
private double score;
private double percentage;
private long date;
public ScoreTO(){}
public ScoreTO(double score, double percentage, long date){
    this.score = score; this.percentage = percentage; this.date=date;
}

public double getScore() {
    return score;
}

public void setScore(double score) {
    this.score = score;
}

public double getPercentage() {
    return percentage;
}

public void setPercentage(double percentage) {
    this.percentage = percentage;
}

public long getDate() {
    return date;
}

public void setDate(long date) {
    this.date = date;
}

}

And there is how I try to catch request in Spring Controller:

@Controller
@RequestMapping(value="/score")
    public class ScoreController {

    (...)

    @RequestMapping(value="/scores", method= RequestMethod.POST)
    @ResponseBody
    public String saveScore(@RequestBody ScoreTO scoreTO){
        scoreService.saveScore(scoreTO.getScore(), scoreTO.getPercentage(), 
                new Date(scoreTO.getDate()));
        return "";
    }
}

But if I try to send it, I got this error in browser console: POST http://localhost:8084/wpisywarkaAngular/score/scores/[object%20Object] 404 (Not Found) What am I doing wrong? I'll we very happy if anybody help me - thank you in advance.

1 Answer 1

6

you have to use all instead of one, another solution can be using customPOST...

Restangular.all("scores").post(scoreTO);
Sign up to request clarification or add additional context in comments.

Comments

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.