SpringMVC中手动转json

时间:2021-06-02 18:44:34   收藏:0   阅读:0

单独json化一个对象,压缩为null的字段

   @RequestMapping("/toDoListApproval")
    public void toDoListApproval(String id, HttpServletResponse response) throws Exception {
        Object responseResult = xxxService.getById(id);
        response.setHeader("Content-Type","application/json;charset=UTF-8");
        ServletOutputStream out = response.getOutputStream();
        IOUtils.write(JSON.toJSONString(responseResult).getBytes("UTF-8"),out);
        out.flush();
    }
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!