如何从控制器SPRING MVC中的地图获取数据

时间:2013-11-19 08:13:44

标签: java javascript jsp jquery spring-mvc

如何从控制器SPRING MVC中的地图获取数据

请帮助我如何在控制器中获取数据映射SPRING MVC我把数据映射就像那样 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>   

这是我的控制器##

@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:/";


    }

1 个答案:

答案 0 :(得分:0)

尝试更改

        @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";
        }

<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>

另外,不要忘记将Jackson JSON Processor放在classpath