Spring MVC 同一个方法同时返回view或json
https://blog.csdn.net/zzg1229059735/article/details/50854778
- @RequestMapping(value = "/htmlorjson/{type}", method = {RequestMethod.GET, RequestMethod.POST})
- public ModelAndView ajaxPaymentBatchApproveProcess(@PathVariable String type)
- {
- if ("html".equals(type))
- {
- //index表示指定路径下的jsp页面的名称
- ModelAndView mav = new ModelAndView("index");
- return mav;
- }
- else
- {
- ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
- mav.addObject("result", "failed");
- return mav;
- }
- }