首页 > 编程语言 > 详细

SpringMVC返回json字符串(非注解方式)

时间:2017-03-14 21:31:16      阅读:238      评论:0      收藏:0      [点我收藏+]


这里采用的是非注解形式,相当于注解中的@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;
    }


本文出自 “JianBo” 博客,转载请与作者联系!

SpringMVC返回json字符串(非注解方式)

原文:http://jianboli.blog.51cto.com/12075002/1906408

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!