public String play() throws IOException { Song song = songService.findById(model.getSongId()); JsonConfig jc = new JsonConfig(); jc.setExcludes( new String[] { "recorder", "copyright", "size", "initiateName", "keyword", "date", "description", "singer" }); JSONObject jsonObject = JSONObject.fromObject(song, jc); String json = jsonObject.toString(); System.out.print(json); ServletActionContext.getResponse().setContentType("text/json;charset=UTF-8"); System.out.println(json); ServletActionContext.getResponse().getWriter().print(json); return NONE; }
public String query() throws IOException { List<Song> songs = songService.findSongs(); JsonConfig jc = new JsonConfig(); jc.setExcludes( new String[] { "recorder", "copyright", "size", "initiateName", "keyword", "date", "description", "singer" }); JSONArray jsonArray = JSONArray.fromObject(songs, jc); String json = jsonArray.toString(); System.out.print(json); ServletActionContext.getResponse().setContentType("text/json;charset=UTF-8"); System.out.println(json); ServletActionContext.getResponse().getWriter().print(json); return NONE; }
public String getWorkMainById(String wmId) { WorkMain workMain = this.workManageDaoImpl.getWorkMainById(wmId); JsonConfig config = new JsonConfig(); config.setExcludes(new String[] {"workItems"}); JSONObject json = JSONObject.fromObject(workMain, config); return json.toString(); }
/** * 除去不想生成的字段(特别适合去掉级联的对象)+时间转换 * * @param excludes 除去不想生成的字�? * @param datePattern * @return */ public static JsonConfig configJson(String[] excludes, String datePattern) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setExcludes(excludes); jsonConfig.setIgnoreDefaultExcludes(true); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor(datePattern)); return jsonConfig; }
public void queryMsgCenter() { PrintWriter out = null; JSONObject json = new JSONObject(); try { request.setCharacterEncoding("utf-8"); response.setContentType("text/json"); response.setCharacterEncoding("utf-8"); out = response.getWriter(); String serialnumid = request.getParameter("serialnumid"); Serialnumber serialnumber = serialNumService.Find(serialnumid); if (serialnumber == null) { json.put("state", 2); json.put("info", "找不到此序列号的信息"); json.put("serialnumid", serialnumid); out.print(json); out.close(); return; } JSONArray locfecnce = this.getElcInfoJson(serialnumber.getSerialnumber()); JSONArray detach = this.getDetachJson(serialnumber.getSerialnumber()); JSONArray fee = this.getFeeBalanceJson(serialnumid); JSONArray battery = this.getBatteryJson(serialnumber.getSerialnumber()); JsonConfig jsonSerialNumConfig = Jsonconf.getSertialNumJsonConf(request); jsonSerialNumConfig.setExcludes( new String[] {"floglastip", "fphonetime", "fqrcode", "id", "fislostinfo", "fislosttime"}); json.put("state", 1); json.put("info", "成功查询"); json.put("serialNumber", JSONArray.fromObject(serialnumber, jsonSerialNumConfig)); json.put("notifyFecnce", locfecnce); json.put("nofityDetach", detach); json.put("notifyFee", fee); json.put("notifyBattery", battery); } catch (Exception e) { json.put("state", -1); json.put("info", e.getMessage()); json.put("serialNumber", null); json.put("notifyFecnce", null); json.put("nofityDetach", null); json.put("notifyFee", null); json.put("notifyBattery", null); } finally { out.print(json); out.close(); } }
public String getWorkItemsById(String wmId) { List<WorkItem> workItems = this.workManageDaoImpl.getWorkItemsById(wmId); JsonConfig config = new JsonConfig(); config.setExcludes(new String[] {"workMain"}); config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessImpl("yyyy/MM/dd")); JSONArray data = JSONArray.fromObject(workItems, config); JSONObject json = new JSONObject(); json.put("datas", data); json.put("results", workItems.size()); return json.toString(); }
private JSONArray getBatteryJson(String serialNumber) { JSONArray arrayObj = null; LocationInfo battery = liDao.findBySeriaNumber(serialNumber); JsonConfig jconfig = Jsonconf.getCommonJsonConf(); jconfig.setExcludes(new String[] {"location", "text", "lng", "lat", "id", "faddtime"}); arrayObj = JSONArray.fromObject(battery, jconfig); return arrayObj; }
// 手表脱落最新 private JSONArray getDetachJson(String serialNumber) { JSONArray arrayObj = null; HashMap<String, String> mapSerial = new HashMap<String, String>(); mapSerial.put("FSNID", serialNumber); List<SerialnumberDetach> listDetach = serialNumService.ListSerialnumberDetach(0, 1, mapSerial); JsonConfig jconfig = Jsonconf.getCommonJsonConf(); jconfig.setExcludes( new String[] {"fincreaseid", "ffieldstatus", "fsnid", "fuserid", "fdetachid"}); arrayObj = JSONArray.fromObject(listDetach, jconfig); return arrayObj; }
// 电子围栏进出 private JSONArray getElcInfoJson(String serialNumber) { JSONArray arrayObj = new JSONArray(); LocElectfenceDaoIml locelect = new LocElectfenceDaoIml(); HashMap<String, String> queryMap = new HashMap<String, String>(); queryMap.put("serialNumber", serialNumber); List<LocElectfence> listLocElectfence = locelect.GetAll(1, 2, queryMap); if (!listLocElectfence.isEmpty()) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor( java.sql.Timestamp.class, new JsonValueProcessor() { private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // new // SimpleDateFormat("yyyy-MM-dd"); public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) { return value == null ? "" : sd.format(value); } public Object processArrayValue(Object value, JsonConfig jsonConfig) { return null; } }); jsonConfig.setExcludes( new String[] { "faddtime", "feltfenceid", "feltlatitude", "feltlongitude", "ffieldstatus", "fincreaseid", "flatitude", "flocfenid", "flongitude", "battery" }); arrayObj = JSONArray.fromObject(listLocElectfence, jsonConfig); } return arrayObj; }
@RequestMapping("loadVersion.htm") public void loadVersion(HttpServletRequest request, HttpServletResponse response) throws Exception { String projectId = request.getParameter("projectId"); Project project = aService.findById(Project.class, Integer.parseInt(projectId)); DetachedCriteria dCriteria = DetachedCriteria.forClass(Version.class); dCriteria.add(Restrictions.eq("project", project)); List<Version> list = new ArrayList<Version>(); list = aService.queryAllOfCondition(Version.class, dCriteria); System.out.println("version list size " + list.size()); JsonConfig config1 = new JsonConfig(); config1.setExcludes(new String[] {"project", "tasks", "affectedVersions"}); JSONArray json = JSONArray.fromObject(list, config1); PrintWriter pt = response.getWriter(); pt.write(json.toString()); pt.close(); }
@POST @At("/ht/pamlist") @Ok("json") public JSONObject list(@Param("..") Pages page, String sid) { JSONObject json = new JSONObject(); json.put(Constant.SUCCESS, true); List<Record> list = baseService.dao.query(sid + ":parameterID", null, page.getNutzPager()); json.put(Constant.TOTAL, baseService.dao.count(sid)); JsonConfig cfg = new JsonConfig(); cfg.setExcludes(new String[] {"station", "createDate"}); JSONArray array = new JSONArray(); Station sa = new Station(); sa.setId(sid); sa = baseService.dao.fetch(sa); for (Record rd : list) { Parameter pm = this.record2Object(rd); JSONObject item = JSONObject.fromObject(pm, cfg); if (null != sa) { item.put("stationName", sa.getName()); } else { item.put("stationName", "无"); } item.put("ID", pm.getParameterID()); item.put( "createDate", null != pm.getCreateDate() ? DateUtil.convertDateToString(pm.getCreateDate(), DateUtil.pattern2) : ""); item.put("Es", pm.getEs()); item.put("Fmin", pm.getFmin()); item.put("M3000F1", pm.getM3000F1()); item.put("M3000F2", pm.getM3000F2()); array.add(item); } json.put(Constant.ROWS, array); return json; }
public String getWorkMainPage(int start, int limit, String userId) { JSONObject json = new JSONObject(); try { List<WorkMain> workMains = workManageDaoImpl.getWorkMainPage(start, limit, userId); int workMainNum = workManageDaoImpl.getWorkMainPageNum(userId); JsonConfig config = new JsonConfig(); config.setExcludes(new String[] {"workItems"}); config.registerJsonValueProcessor(Date.class, new DateJsonValueProcessImpl("yyyy/MM/dd")); JSONArray data = JSONArray.fromObject(workMains, config); json.put("datas", data); json.put("results", workMainNum); json.put("start", start); json.put("limit", limit); } catch (Exception e) { e.printStackTrace(); } return json.toString(); }
private JSONArray getFeeBalanceJson(String serialnumid) { JSONArray arrayObj = null; HashMap<String, String> mapSerial = new HashMap<String, String>(); mapSerial.put("FSNID", serialnumid); List<SerialnumberFee> listFee = serialNumService.ListSerialnumberFee(0, 1, mapSerial); JsonConfig jconfig = Jsonconf.getCommonJsonConf(); jconfig.setExcludes( new String[] { "fincreaseid", "freltable", "frelval", "foperator", "foperatestate", "foperatetime", "ffieldstatus" }); arrayObj = JSONArray.fromObject(listFee, jconfig); return arrayObj; }
public void queryLocEleChange() { PrintWriter out = null; JSONObject json = new JSONObject(); try { request.setCharacterEncoding("utf-8"); response.setContentType("text/json"); response.setCharacterEncoding("utf-8"); out = response.getWriter(); String serialNumber = request.getParameter("serialNumber"); String areaNumber = request.getParameter("areaNumber"); String areaName = request.getParameter("areaName"); areaName = Tools.DecodeUtf8String(areaName); LocElectfenceDaoIml locelect = new LocElectfenceDaoIml(); try { HashMap<String, String> queryMap = new HashMap<String, String>(); queryMap.put("serialNumber", serialNumber); queryMap.put("areaNumber", areaNumber); queryMap.put("areaName", areaName); List<LocElectfence> listLocElectfence = locelect.GetAll(1, 2, queryMap); // List<LocElectfence> listLocElectfence= new // ArrayList<LocElectfence>(); System.out.println(listLocElectfence.size()); if (!listLocElectfence.isEmpty()) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor( java.sql.Timestamp.class, new JsonValueProcessor() { private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // new // SimpleDateFormat("yyyy-MM-dd"); public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) { return value == null ? "" : sd.format(value); } public Object processArrayValue(Object value, JsonConfig jsonConfig) { return null; } }); jsonConfig.setExcludes( new String[] { "faddtime", "feltfenceid", "feltlatitude", "feltlongitude", "ffieldstatus", "fincreaseid", "flatitude", "flocfenid", "flongitude" }); // jsonArr.add(JSONArray.fromObject(listLocElectfence,jsonConfig)); // jsonArr.add(listLocElectfence); json.put("state", 1); json.put("info", "成功查询"); json.put("data", JSONArray.fromObject(listLocElectfence, jsonConfig)); } else { json.put("state", 1); json.put("info", "成功查询,数据为空"); json.put("data", null); } } catch (RuntimeException ex) { json.put("state", 1); json.put("info", ex.getMessage()); json.put("data", null); } } catch (Exception e) { json.put("state", -1); json.put("info", e.getMessage()); json.put("data", null); } finally { out.print(json); out.close(); } }
static { jsonConfig.setExcludes(new String[] {"retweetedStatus"}); jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Properties prop = new Properties(); InputStream in = Utility.class.getClassLoader().getResourceAsStream("config.xml"); prop.loadFromXML(in); String goods_rushby = prop.getProperty("goods_rushby"); StringBuilder strSql = new StringBuilder(); strSql.append(" select tmp.* from "); strSql.append(" (SELECT "); strSql.append( " c.goods_id, "); strSql.append( " c.goods_name, "); strSql.append( " (select g.price from tdd_goods_spec g where g.goods_id = c.goods_id LIMIT 0,1) price, "); strSql.append( " c.mark_price, "); strSql.append( " c.default_image420 default_image "); strSql.append( " FROM "); strSql.append( " tdd_goods c "); strSql.append( " LEFT JOIN tdd_store d ON c.store_id = d.store_id "); strSql.append( " WHERE "); strSql.append( " c.if_rob = 1 "); strSql.append( " AND c.closed = 0 "); strSql.append( " AND d.state = 1 and c.goods_id in (" + goods_rushby + ") "); strSql.append( " limit 0,4 ) tmp "); // strSql.append(" AND c.goods_id = p_goods_id "); List<Map<String, Object>> lstResult = SqlUtility.getInstance().getQueryResult(strSql.toString()); /* * Properties prop = new Properties(); * * InputStream in = * Utility.class.getClassLoader().getResourceAsStream("config.xml"); * prop.loadFromXML(in); String goods_rushby = * prop.getProperty("goods_rushby"); * System.out.println("goods_rushby="+goods_rushby); List<Map<String, * Object>> lstAfter = new ArrayList<Map<String,Object>>(); * List<Map<String, Object>> lstBefore = new * ArrayList<Map<String,Object>>(); for (Map<String, Object> map : * lstResult) { String g_id = * ConvertUtil.convertStr((Long)map.get("GOODS_ID")); * System.out.println( * "g_id="+g_id+"||"+(StringUtils.indexOfAny(goods_rushby, * ConvertUtil.convertStr((Long)map.get("GOODS_ID"))) == -1)); if * (StringUtils.indexOfAny(goods_rushby, * ConvertUtil.convertStr((Long)map.get("GOODS_ID"))) == -1) { * lstAfter.add(map); } else { lstBefore.add(map); } * * } * * System.out.println("after="+lstAfter.get(0).get("GOODS_ID")); * System.out.println("before="+lstBefore.get(0).get("GOODS_ID")); * lstResult.clear(); lstResult.addAll(lstAfter); * lstResult.addAll(lstBefore); */ JsonConfig jc2 = new JsonConfig(); jc2.setExcludes(new String[] {}); String json = JSONArray.fromObject(lstResult, jc2).toString(); JSONObject jsonObject = new JSONObject(); jsonObject.put("list", json); System.out.println("GetRushBy=" + jsonObject); response.setContentType("text/plain;charset=UTF-8"); response.getWriter().write(jsonObject.toString()); }
private static void setConfig(JsonConfig jsonConfig, String[] excludes) { jsonConfig.setExcludes(excludes); jsonConfig.setIgnoreDefaultExcludes(false); jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); }
public static JsonConfig configJson() { JsonConfig jcf = new JsonConfig(); jcf.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor()); jcf.setExcludes(new String[] {"dlogs"}); return jcf; }