struts,springmvc的属性驱动和模型驱动(包括ajax)

struts依赖get set实现属性驱动,模型驱动(类级别的属性):

模型应用(前后互传)

<th>手机号码:</th>

<td>

<input type="text" name="queryOrderReq.mobile" id="mobile" value="<s:property value="queryOrderReq.mobile"/>" />

</td>

private QueryOrderReq queryOrderReq = new QueryOrderReq();

public QueryOrderReq getQueryOrderReq() {

return queryOrderReq;

}

public void setQueryOrderReq(QueryOrderReq queryOrderReq) {

this.queryOrderReq = queryOrderReq;

}

ajax返回也一样(类似属性驱动)

private String result;

public String additional1() throws FileNotFoundException, IOException, NoSuchAlgorithmException, InvalidKeyException, XmlPullParserException {

//InputStream is = new FileInputStream(fileName.getPath());

InputStream sbs = null;

HttpServletRequest request = ServletActionContext.getRequest();

imgData = request.getParameter("imgData");

JSONObject finalJSONObject = new JSONObject();

if (imgData != null) {

sbs = new ByteArrayInputStream(imgData.getBytes());

Minoperator.saveObject(sbs, bluckname, rspStr);

}

//else{

//Minoperator.saveObject(is,fileNameFileName);

//}

finalJSONObject.put("returnCode", "1");

System.out.println("进入补充资料" + fileNameFileName);

System.out.println("进入补充资料1111" + imgData);

result = finalJSONObject.toJSONString();

return SUCCESS;

}

<action name="additional1" class="weixinPublicAction" method="additional1">

<result type="json">

<param name="contentType">application/json</param>

<param name="root">result</param>

</result>

</action>

 function uploadImage(imageData,tag){

  alert(5);

  $.ajax({

  url: '${ctx}/itm/salefollow/additional1.action',

  data: {

  rspStr:"111.png",

  imgData: imageData ,// 图片数据流

  bluckname:"test"

  },

  dataType: 'json',

  type: 'post',

  success: function(data) {

  var dataJsonObject = JSON.parse(data);

  if (dataJsonObject.returnCode == 1 ) {

  var img = '#image' + tag;

  $(img).attr('src',data.imageUrl);

  }else{

  alert('图片上传失败!');

  }

  },

  error: function(xhr, type, errorThrown) {

  alert('网络异常,请稍后再试!');

  }

  });

  }

springmvc依赖@requestboday,@responseboday(不需要变量的set,get)

@requestboday参数放入实体

@responseboday ,实体json返回

相关推荐