给你个例子:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Employee employee = (Employee) request.getSession().getAttribute("employee")
FolderService fs = new FolderServiceImpl()//接口以及接口的实现
List<Folder>folderList=fs.findParentFolder(employee.getEmpNo())//从数据库里拿出个List
JSONArray arr=JSONArray.fromObject(folderList)//转成JSON
response.setCharacterEncoding("UTF-8")
response.getWriter().print(arr)//输出到前台
}
下载gson.jar。可以使用jsonobject将map等对象转换成json,比较方便,但是效率一般,使用stringbuffer的append方法拼接json字符串效率最佳。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)