小白羊

导航

Spring MVC 同一个方法同时返回view或json

https://blog.csdn.net/zzg1229059735/article/details/50854778

  1. @RequestMapping(value = "/htmlorjson/{type}", method = {RequestMethod.GET, RequestMethod.POST})  
  2.     public ModelAndView ajaxPaymentBatchApproveProcess(@PathVariable String type)  
  3.     {  
  4.         if ("html".equals(type))  
  5.         {  
  6.              //index表示指定路径下的jsp页面的名称  
  7.             ModelAndView mav = new ModelAndView("index");  
  8.             return mav;  
  9.         }  
  10.         else  
  11.         {  
  12.             ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());  
  13.             mav.addObject("result", "failed");  
  14.             return mav;  
  15.         }  
  16.     }  

posted on 2018-05-21 23:00  小白羊  阅读(766)  评论(0编辑  收藏  举报