controller 返回信息到页面,出现乱码

  • Post author:
  • Post category:其他


代码如下

    @ResponseBody
    @RequestMapping(value = "/addStudent",method = RequestMethod.GET)
    public String addStudent(Student student){
        if (ssi.addStudent(student)) {
            return "<script>alert('添加成功');location.href='/sc/list'</script>";
        }
        return "<script>alert('添加失败');location.href='addStudent'</script>";
    }

运行效果如下

解决方法如下

    @ResponseBody
    @RequestMapping(value = "/addStudent",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
    public String addStudent(Student student){
        if (ssi.addStudent(student)) {
            return "<script>alert('添加成功');location.href='/sc/list'</script>";
        }
        return "<script>alert('添加失败');location.href='addStudent'</script>";
    }



版权声明:本文为qq_41016818原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。