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

阅读更多

 

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

 

模型应用(前后互传)

手机号码:

" />

 

 

 

 

 

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;

}

 

application/json

result

 

 

 

 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返回

 

 

你可能感兴趣的:(mvc)