开发者社区> 问答> 正文

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

}

展开
收起
杨冬芳 2016-07-04 11:32:00 3696 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Vue.js 在前端服务化上的探索与实践 立即下载
阿里文娱大前端技术实践 立即下载
前端代码是怎样智能生成的 立即下载