liyuan_cw 2013-05-29 09:54 采纳率: 100%
浏览 3536

这段代码输出保存在数据库中的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);

}
  • 写回答

1条回答 默认 最新

  • WorldMobile 2015-10-28 10:52
    关注

    参考这个把Json数据从数据库取到前端,然后解析显示
    Ajax返回Json在Java中的实现
    http://www.cnblogs.com/lsnproj/archive/2012/02/09/2341524.html

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog