2 liyuan cw liyuan_cw 于 2013.05.29 17:54 提问

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

lzp_lrp
lzp_lrp   Ds   Rxr 2015.10.28 18:52

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!