码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:返回json字符串 非注解


这里采用的是非注解形式,相当于注解中的@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字符串(非注解方式)

标签:返回json字符串 非注解

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!