Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple parameters (objects) from angular to spring/hilbernate

Angular:

function(team, team) { return this.http.put('/api/tradeTeam/', team, 
     team2).map(res => res.json()); }

Spring/Hibernate

@RestController
@Controller
public class MainController {
    @RequestMapping(value = "/api/tradeTeam/", method = RequestMethod.PUT)  
    public List<Team> TradeTeam(@RequestBody Team team, Team team2) {       
        return teamService.TradeTeam(team, team2);      
    }
}

What am I doing wrong? My Service is set up correctly.
My error is:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

like image 214
Chris22311 Avatar asked Jul 15 '26 12:07

Chris22311


1 Answers

The problem is that you are passing the team2 as a third parameter for the http.put function, which is taken as options (not for body where you need it).

You should send something like that (and I think this will need some more work also on the backend)

function(team, team2) { 
    return this.http.put('/api/tradeTeam/', {teams: [team, team2]})
       .map(res => res.json()); 
}

See: Angular HTTP Client Docs

like image 72
Roman Šimík Avatar answered Jul 17 '26 17:07

Roman Šimík