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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题