ext ajax与struts传json对象 实例
ext ajax json与struts实例
ext的javascript代码:
//提交修改 function submitUpdate(grid,colIndex,rowIndex,id){ //后台semanticsBean var sentence = Ext.getCmp('updateSentence').getValue(); var template = Ext.getCmp('updateTemplatesql').getValue(); var tableids = Ext.getCmp('updateTableids').getValue(); var jsonBean = { 'bean.id' : id, 'bean.sentence' : sentence, 'bean.template' : template, 'bean.tableids' : tableids } var bean = {id:id,sentence:sentence,template:template,tableids:tableids}; Ext.Ajax.request({ url:'./modifySemantics', params:jsonBean, success:function(r,o){ reRenderTable(grid,colIndex,rowIndex,bean); }, failure:function(){ Ext.Msg.alert("更新有误","更新有误,当前数据过旧,请刷新重试"); } }); }
struts配置文件:
<!-- 更新语义库记录 --> <action name="modifySemantics" class="com.xxxx.vbap.nl.action.NLManageAction" method="updateSemanticsList"> </action>
strut java代码:
类中属性
// 前台传输实体bean private SemanticsSqlTemp bean = new SemanticsSqlTemp();
public String updateSemanticsList(){ try{ if(this.bean == null || this.bean.getId() == 0){ logger.error("更新语义库sql模板报错,传输数据缺少ID"); return Action.NONE; } ArrayList<Object> keyvalueList = new ArrayList<Object>(); ArrayList<Class<?>> classtypeList = new ArrayList<Class<?>>(); bean.setUpdateData(keyvalueList, classtypeList); String sql = "update sql_template_set set sentence = ?,templatesql = ?,tableids = ? where id = ?"; NLSqlAnalysis.updateByID(sql, bean, keyvalueList, classtypeList); return Action.NONE; }catch (Exception e) { logger.error("更新语义库sql模板报错",e); return Action.ERROR; } }
这样就可以让struts接收json对象
再附上一个解析传回的json对象代码
function showSemanticsList(type,renderDivID) { //var showradio = Ext.getCmp("showRadioGroup"); //var showtype = getRadioInputValue(showradio);//获取数据标志 Ext.Ajax.request({ url:'./showSemantics', params:{ showType:type }, success : function(r,o){ var re = Ext.decode(r.responseText); if(re.length>0) showSemanticsData(type,re,renderDivID);//TODO: else{ document.getElementById(renderDivID).innerHTML = ""; Ext.Msg.alert("无所选数据"); } }, failure : function(){ Ext.Msg.alert("语义库查询有误","语义库查询有误"); } }); }
在js中解析json对象:
function showItem(grid,colIndex,rowIndex){ var id = rowIndex.data.id; Ext.Ajax.request({ url:'./getSemantics', params:{id:id}, success:function(r,o){ var re = Ext.decode(r.responseText); showItemEditPage(2,grid,colIndex,rowIndex,re); }, failure:function(){Ext.Msg.alert("语义查询有误","语义查询有误");} }); }
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05