问题描述
- 这段代码输出保存在数据库中的json格式数据怎么用java代码在前端显示出来
-
public class SaveHotKeySkillReq extends CommandBase {@Resource //数据库操作 private EntityManager em; protected void execute() throws GMessageException { CRequesthotKeyChange msg = pak.readMsg(CRequesthotKeyChange.class); int item_id= msg.item_id; int index = msg.index; ActorSetting actorSetting = em.createQuery(ActorSetting.class).setParameter("actorId", actorSession.getActorId()).getSingleResult(); String skill = actorSetting.getSkillSetting(); JSONArray jsonArray = null; if(skill != null && !skill.equals("")){ jsonArray = JSONArray.fromObject(skill); } if(jsonArray == null){ jsonArray = new JSONArray(); } boolean isupdate = false; for (Object object : jsonArray) { JSONObject json = (JSONObject)object; if(json.getInt("index") == index){ json.put("item_id", item_id); isupdate = true; } } if(isupdate == false){ JSONObject json = new JSONObject(); json.put("index", index); json.put("item_id", item_id); jsonArray.add(json); } if (actorSetting == null) { throw new GMessageException(GMessageException.ACTOR_DATA_ERROR); } actorSetting.setSkillSetting(skill); em.merge(actorSetting); }
解决方案
参考这个把Json数据从数据库取到前端,然后解析显示
Ajax返回Json在Java中的实现
http://www.cnblogs.com/lsnproj/archive/2012/02/09/2341524.html
时间: 2024-10-31 16:03:06