1、需要引入的包:
commons-beanutils.jar
commons-collections-3.1.jar
commons-lang.jar
json-lib-2.3-jdk15.jar
2、代码
JSONArray jsonArray = new JSONArray();
Session session = sessionFactory.getCurrentSession();
String querySQL = " from SerUnit";
List<SerUnit> list = session.createQuery(querySQL).list();
JsonConfig jsonConfig = new JsonConfig(); // 建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false); // 设置默认忽略
jsonConfig.setExcludes(new String[] { "opStations" }); //忽略字段
jsonArray = JSONArray.fromObject(list, jsonConfig);