ajax前后台上下文

========后台到前台就是一个标准的Stringjson串,真正到了前台变成对象会对象数组===========

publicStringqueryCutOverOrderById(){

Stringid=model.getId();

CutOverOrdera=newCutOverOrder();

List<CutOverOrder>tr=newArrayList<CutOverOrder>();

tr=this.getService().queryCutOverOrderById(id);

if(tr.size()>0){

a=tr.get(0);

JsonConfigconfig=newJsonConfig();

config.setExcludes(newString[]{"processLogs"});

Stringjson=JSONArray.fromObject(a,config).toString();

HttpServletResponseresponse=ServletActionContext.getResponse();;

response.setCharacterEncoding("utf-8");

//ServletOutputStreamout=null;

BufferedWriterwrite=null;

try

{

write=newBufferedWriter(newOutputStreamWriter(response

.getOutputStream(),"UTF-8"));

write.write(json);

//out=response.getOutputStream();

//out.write(json.getBytes());

}

catch(IOExceptione)

{

e.printStackTrace();

}

finally

{

try{

//out.flush();

//out.close();

write.flush();

write.close();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

returnnull;

}else{

returnnull;

}

}

前台:

$.ajax({

type:'post',

url:url,

async:false,

data:null,

dataType:'json',

success:function(data){

vara=eval(data);

if(data){

for(vari=0;i<a.length;i++){

s[i]=a[i].stage;

t[i]=a[i].recordTime;

inc[i]=a.cnName;

}

}

},

error:function(){

//$.message("失败");

}

});

前台到后台:

$.ajax({

type:'post',

url:'<%=csgui%>',

data:'dataArraySave='+JSON.stringify(dataArraySave),

dataType:'json',

success:function(data){

$.message("成功");

$("#list2").grid('reload');

},

error:function(){

$.message("失败");

}

});

@Transactional

publicvoidgetJson(){

HttpServletRequestrequest=ServletActionContext.getRequest();

StringdataArraySave=request.getParameter("dataArraySave");

String[]a=JsonUtil.jsonStrToStringArray(dataArraySave);

Params[]b=(Params[])JsonUtil.jsonStrToArray(dataArraySave,Params.class);

List<Params>c=newArrayList<Params>();

for(inti=0;i<b.length;i++){

c.add(b[i]);

}

this.getService().saveParams(c);

}

===============前台到后台可能会传一个list<object>,list<string[]这时要将他们转化为Sting作为参数传到后台>============

另一种:

Stringui=request.getContextPath()+"/interface-cnfig!intesvae.json?smal=";

functiongetj(){

varids=[];

vardataArraySave=[],json="";

varsel=$("#list2").grid("option","selarrrow");

ids=$("#list2").grid("getDataIDs");

$.each(sel,function(i){

dataArraySave.push($("#list2").grid("getRowData",sel[i]));

});

textvar=JSON.stringify(dataArraySave);

returntextvar;

}

//这一步将list的记录(每一条一个json)转化为大的json数组

//[{"id":"3","csbs":"666","csmc":"666","cslx":"666"},//{"id":"2","csbs":"66","csmc":"66","cslx":"66"},//{"id":"1","csbs":"//6","csmc":"6","cslx":"6"}]

functionf_new(){

//window.execScript('window.varText='+""+';');

varuu='<%=ui%>';

//alert(uu);

$("#search-form").dialog({

autoOpen:false,

height:'auto',

width:700,

modal:true,

buttons:{

"保存":function(){

vara=getj();

varuui=uu+a;

//alert(uui);

//$("#form11").form("submit");

if($("#form11").form("valid")){

$.ajax({

type:'post',

url:uui,

data:$("#form11").form("formData",false),

dataType:'json',

success:function(data){

$.message("操作成功!"+data.id);

$('#list1').grid('reload');

},

error:function(){

$.message("操作失败!");

}

});

}else{

$.alert("未通过页面校验!")

}

},

"关闭":function(){

$(this).dialog("close");

}

}

});

publicStringintesvae(){

Stringid="";

HttpServletRequestrequest=ServletActionContext.getRequest();

id=this.getService().saveIntcfg(model);

Stringa=request.getParameter("smal");

if(a!=""||a!="["+"]"){

Params[]b=(Params[])JsonUtil.jsonStrToArray(a,Params.class);

List<Params>c=newArrayList<Params>();

for(inti=0;i<b.length;i++){

b[i].setJkid(id);

c.add(b[i]);

}

this.getService().saveParams(c);

}

returnid;

}

================保存对应的form=========

<divid="search-form"title="接口添加界面"style="display:none">

<cui:formid="form11"name="form"action="<%=ui%>">

<tableheight="100%">

<trstyle="vertical-align:top;height:45px">

<tdstyle="text-align:left;padding-left:10px;"height="15">

<divstyle="float:left;padding-top:8px;"><label>&nbsp;接口名称:</label></div>

<divstyle="float:left;padding-top:8px;"><cui:inputid="interfacename"

name="interfacename"placeholder="接口名称"value=""width="200"/></div>

<divstyle="float:left;padding-top:8px;"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数据类型:</label></div>

<divstyle="float:left;padding-top:8px;"><cui:comboboxid="datatype"

name="datatype"width="200"value=""emptyText="请选择"

data="combo_data"></cui:combobox></div>

</td>

</tr>

<trstyle="vertical-align:top;height:45px">

<tdstyle="text-align:left;padding-left:10px;">

<divstyle="float:left;padding-top:8px;"><label>&nbsp;接口地址:</label></div>

<divstyle="float:left;padding-top:8px;"><cui:inputid="interfaceadrss"

name="interfaceadrss"value=""width="200"/></div>

<divstyle="float:left;padding-top:8px;"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接口类型:</label></div>

<divstyle="float:left;padding-top:8px;"><cui:comboboxid="interfacetype"

name="interfacetype"width="200"value=""

emptyText="请选择"data="combo_data_interface"></cui:combobox></div>

</td>

</tr>

<trstyle="vertical-align:top;height:45px">

<tdstyle="text-align:left;padding-left:10px;">

<divstyle="float:left;"><label>&nbsp;接口厂商:</label>

<!--<cui:combobox

id="getway"name="getway"required="true"width="200"value=""

emptyText="请选择"data="combo_data_get"></cui:combobox>

-->

<cui:input

id="interfacefac"name="interfacefac"placeholder="接口厂商"value=""width="200"/>

</div>

<divstyle="float:left;padding-top:8px;"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户认证:</label><cui:input

id="confirm"name="confirm"placeholder="用户认证"value=""width="200"/></div>

</td>

</tr>

<trstyle="vertical-align:top"id="param">

<td>

<divstyle="float:left;padding-top:8px;"><label>&nbsp;&nbsp;&nbsp;是否同步:</label>

</div>

<divstyle="float:left;padding-top:8px;">

<cui:radiolistid="sftb"column="4"

name="sftb"value="none"data="radiolistdata">

</cui:radiolist>

</div>

</td>

</tr>

<trstyle="vertical-align:top"id="param">

<tdstyle="text-align:right;padding-left:10px;">

<divstyle="float:left;"><label>&nbsp;参数类型:</label></div>

</td>

</tr>

<tr>

<tdstyle="float:left;">

<divstyle="float:left;">

<inputtype="button"class='btnviewcoral-btn-blue'id="add"value="添加行"></input>

</div>

</td>

<tdstyle="float:left;">

<divstyle="float:left;">

</div>

<divstyle="float:left;"><inputtype="button"class='btnviewcoral-btn-blue'id="edite"value="编辑行"></input></div>

<divstyle="float:left;">

<inputtype="button"class='btnviewcoral-btn-blue'id="saveEdite"value="保存编辑"></input>

</div>

</td>

</tr>

<tr>

<tdcolspan="4">

<cui:gridid="list2"onComplete="gridoncomplete"datatype="local"multiselect="true">

<cui:gridCols>

<cui:gridColname="id"hidden="false"editable="true"align="center"width="80">序号</cui:gridCol>

<cui:gridColname="csbs"editable="true"align="center"width="160">参数标识</cui:gridCol>

<cui:gridColname="csmc"editable="true"align="center"width="160">参数名称</cui:gridCol>

<cui:gridColname="cslx"editable="true"align="center"width="160">参数类型</cui:gridCol>

<!--<cui:gridColname="cz"editable="true"align="center"width="120">操作</cui:gridCol>

--></cui:gridCols>

<cui:gridPagergridid="list2"/>

</cui:grid>

<!--<cui:gridid="list2"datatype="local"multiselect="true"rownumbers="true">

<cui:gridCols>

<cui:gridColname="id"editable="true"hidden="true"width="100">id</cui:gridCol>

<cui:gridColname="name"editable="true"width="80">员工帐号</cui:gridCol>

<cui:gridColname="src"editable="true"width="80">图片路径</cui:gridCol>

<cui:gridColname="age"editable="true"width="80">年龄</cui:gridCol>

<cui:gridColname="createtime"editable="true"edittype="date"width="80">时间点1</cui:gridCol>

<cui:gridColname="createtime1"editable="true"edittype="date"width="80">时间点2</cui:gridCol>

</cui:gridCols>

</cui:grid>

--></td>

</tr>

</table>

</cui:form>

</div>

相关推荐