Code example for ModelAndView

Methods: addObject

0
    private SocialUserService socialUserService;
 
    @RequestMapping("/") 
    public ModelAndView home() {
 
        ModelAndView modelAndView = new ModelAndView("home");
 
        User user = SecurityUtil.getLoggedInUser();
 
        modelAndView.addObject(user);
 
        // check if the account is connected to any social network accounts 
        ConnectionRepository connectionRepository = socialUserService.createConnectionRepository(user.getUsername());
 
        // only Twitter and Facebook accounts are supported in this app, so check for those specifically 
        List connections = connectionRepository.findConnections("twitter");
 
        // Spring Social allows multiple social network accounts to be connected to one local account 
        // however in this app we are only providing a UI for users to connect one Twitter and one Facebook account 
 
        // so, anything in the list means that the user has connected a Twitter account 
        if (!connections.isEmpty()) {
            modelAndView.addObject("twitterConnected", "true");
        } 
        // same thing, for Facebook 
        connections = connectionRepository.findConnections("facebook");
        if (!connections.isEmpty()) {
            modelAndView.addObject("facebookConnected", "true");
        } 
 
        return modelAndView;
    } 
} 
Experience pair programming with AI  Get Codota for Java