springmvc同方法中响应json报文或view视图

1
2
3
4
5
6
7
8
9
10
11
12
13
@RequestMapping(value = "/test", method =RequestMethod.POST)
public ModelAndView test(String p) {
if("1".equals(p)){//响应JSON
SysUser sysUser = getUser();
ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
mav.addObject(sysUser);
return mav;
}else {//跳转网页
String ssoErrorPage = SMPPropertyUtil.getFrameworkProperty("partner.error.url");
ModelAndView mav = new ModelAndView("redirect:"+ssoErrorPage);
return mav;
}
}