通过Ajax---SpringMVC返回json字符串(非注解方式)

来源:互联网 发布:诺基亚x6软件 编辑:程序博客网 时间:2024/05/16 18:40

这里采用的是非注解形式,相当于注解中的@responseBody

/**     * 根据字符串输出JSON,返回null     *      * @param jsonString     * @return     */    public String ajaxJson(HttpServletResponse response,String jsonString) {        return ajax(response,jsonString, "text/html");    }

/**     * 返回json字符串(非注解形式)     * AJAX输出,返回null     *      * @param content     * @param type     * @return     */    public String ajax(HttpServletResponse response, String content, String type) {        try {            response.setContentType(type + ";charset=UTF-8");            response.setHeader("Pragma", "No-cache");            response.setHeader("Cache-Control", "no-cache");            response.setDateHeader("Expires", 0);            response.getWriter().write(content);            response.getWriter().flush();        } catch (IOException e) {            e.printStackTrace();            logger.error("IOException:", e);        }        return null;    }




阅读全文
0 0
原创粉丝点击