简体   繁体   中英

how to get data from map in controller SPRING MVC

how to get data from map in controller SPRING MVC

Please help me how to get data map in controler SPRING MVC i put the data map to like that map.put("error", "x");

    <script type="text/javascript" >
     function doAjaxPostTeamDelete (team_ID){


         $.ajax({
            type: "POST",
            url: "/controller/deleteTeam",
            data: "teamID=" + team_ID,          
            success: function(response){  
                  // we have the response  
                ****if(x="${error}")//that is point the i have doubt**** 
                                {
                    alert("You Cant Delete");   
                             }      

                }, 
                error: function(e){  
                  alert('Error: ' + e);  
                }    
         });     
     }   
 </script>   

this is my controller##

@RequestMapping(value="/deleteTeam", method=RequestMethod.POST)
    public String editDeleteRecodes(@ModelAttribute NewTeams newTeams, Map<String, Object> map){        
        Teams teams = new Teams();
        teams.setTeamID(newTeams.getTeamID());
        try{
            teamService.delete(teams);
        }catch (DataIntegrityViolationException ex){
            map.put("error", "x");
            //System.out.println("aaaaa");
        }

        return "redirect:/";


    }

Try changing

        @RequestMapping(value="/deleteTeam", method=RequestMethod.GET)
        @ResponseBody
        public String getByIdFromParam(@RequestParam Long teamID) {
         try{
                teamService.delete(new Teams().setTeamID(teamID));
            }catch (DataIntegrityViolationException ex){
                return "error";
            }
            return "sucess";
        }

And

<script type="text/javascript">
     function doAjaxPostTeamDelete (team_ID){
         $.ajax({
            type: "GET",
            url: "/controller/deleteTeam",
            data: "teamID=" + team_ID,          
            success: function(response){  
                if(response="error"){
                    alert("You Cant Delete");   
                }}, 
            error: function(e){  
                alert('Error: ' + e);  
            }    
         });     
     }   
 </script>

Also don't forget to put Jackson JSON Processor in classpath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM