SSM框架添加RESTAPI应用

SSM框架搭建看这篇http://blog.csdn.net/zhshulin/article/details/37956105

当需要把控制类升级为RESTController时,在spring-mvc.xml只需添加一句

  
  
      
     
   
   	
	 
     
      
          
              
                text/html;charset=UTF-8  
             
          
      
      
      
          
              
                   
              
          
      
      
      
          
          
          
         
      
        
          
            
          
            
          
            
     

java原来控制类

@Controller  
@RequestMapping("user")
public class userController {
    @Resource  
    private IUserService userService;  
      
    @RequestMapping("/showUser") 
    public String toIndex(HttpServletRequest request,Model model){  
        int userId = Integer.parseInt(request.getParameter("id"));  
        User user = this.userService.getUserById(userId);  
        model.addAttribute("user", user);  
        return "showUser";  
    } 
}

控制类升级RESTAPI后

@RestController
@RequestMapping("/user")
public class userController {  

	@Resource  
    private IUserService userService;  
      
    @RequestMapping("/{id}")
    public User GETUSER(@PathVariable Integer id){   
        User user = this.userService.getUserById(id);   
        return user;
    } 
}  


你可能感兴趣的:(后端)