首页 > 学院 > 开发设计 > 正文

自己用的各种工具类(不喜勿喷)

2019-11-14 22:17:14
字体:
来源:转载
供稿:网友
自己用的各种工具类(不喜勿喷)

1:List转Json

public static String list2JsonArray(List list) {        StringBuffer str = new StringBuffer("[");        if (list != null && list.size() > 0) {            int len = list.size();            Object map = null;            for (int i = 0; i < len; i++) {                map = list.get(i);                if (i > 0) {                    str.append(",");                }                str.append(JSONUtil.object2json(map));            }        }        str.append("]");        return str.toString();    }

2:Ajax向前端返回json字符串

//向前端返回json字符串    public void outString(String json) {        PRintWriter print = null;        try {            HttpServletResponse response;            response = this.getResponse();            response.setContentType("text/json;charset=UTF-8");            response.setHeader("Cache-Control", "no-cache");            response.setHeader("Pargma", "no-cache");            response.setDateHeader("Expires", 0);            print = this.getResponse().getWriter();            print.write(json);        } catch (IOException e) {            e.printStackTrace();        }    }

先吃饭去了 其他的慢慢补充 嘿嘿


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表