weixin_42393436 2011-01-25 18:11
浏览 1520
已采纳

SpringMVC controller 方法里如何返回JSON消息或跳转页面?

根据执行情况或返回消息或跳转页面:
[code="java"]
@RequestMapping(value = "/signin", method = RequestMethod.POST)
@ResponseBody
public String signin(String code, String password, ModelMap model){
String message = "";
User user = new User();
if(!code.equalsIgnoreCase("000001"))
message = "code:帐号不存在";

    else if(!password.equalsIgnoreCase("123"))
        message = "password:密码错误";

    else{
        model.addAttribute(Constants.SESSION_USER, user);
        message =  "redirect:index.html";
    }
    return message;
}

[/code]

  • 写回答

5条回答 默认 最新

  • linvar 2011-01-26 17:56
    关注

    代码不能这样写...不好看 :wink:
    又要返回字符串,又要跳转,
    在springMVC中不支持这样,重新设计吧,
    可以看一下spring mvc 的文档,
    @ResponseBody已表明你要返回字符流了,
    你又要redirect...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗