============================================================================
spring mvc参数复杂混合传递方式,混合返回方式:
在传递list的实体时如果还要传递其他单个属性这些单个属性要放在requestHeader中,
类似的图片流就放在requestbody中(一般httpclient工具方),后台拿也从requestbody中
@RequestMapping(value="/system/opmRole/Auths")
@ResponseBody
public JSONArray treeRead(@RequestHeader(value="fg") String fg,@RequestHeader(value="id",required=false) String id,@RequestHeader(value="leave") String leave,
@RequestHeader(value="roleId") String roleId,@RequestHeader(value="pId") String pId,@RequestHeader(value="groupId",required=false) String groupId1,
@RequestBody(required=false) List<OpmRolelimit> o){
JsonArray.addAll(treeRead(fg,id,leave,roleId,p.get("ID")+"",groupId,o));
return JsonArray;
}
function appendTable() {
var roleId=$("input[name='roleId']").val();
var leave=$("input[name='leave']").val();
var pId=$("input[name='pId']").val();
var id=$("input[id='idy']").val();
//alert($("input[id='idy']").val());
var dataParent = {
roleId: "1",
leave:"2",
pId:"3",
id:"5"
};
$.ajax({
type: "post",
url: "${pageContext.request.contextPath}/system/opmRole/Auths",
//data: dataParent,
// headers:"{\"id\": \"1\",\"leave\":\"2\",\"roleId\":\"3\",\"pId\":\"5\"}",
beforeSend: function(xhr){///参数方头部
xhr.setRequestHeader('id', id);//注意不同的浏览器这种传头部参数遇到空值会有问题,在后台加required=false
xhr.setRequestHeader('leave', leave);
xhr.setRequestHeader('roleId', roleId);
xhr.setRequestHeader('pId', pId);
xhr.setRequestHeader('fg', "1");
},
//dataType: 'json',
//contentType: "application/json",
success: function (data) {
if(data!=''&&data!=null){
var div1=$("#div1");
var table1=$("<table></table>");
var arr = eval(data);
for(j=0;j<arr.length;j++){
if(arr[j].leave=='1'){
var row =$("<tr></tr>");
var td =$("<td></td>");
td.append($(arr[j].str));
row.append(td);
table1.append(row);
}
var row2 ;
if(arr[j].leave=='2'){
row2 =$("<tr></tr>");
var td =$("<td></td>");
td.append(arr[j].str);
row2.append(td);
table1.append(row2);
}if(arr[j].leave=='3'){
var td =$("<td></td>");
td.append(arr[j].str);
table1.find("tr:last").append(td);
}
}
div1.html(table1);
}else{
alert("你输入的会员编号不存在!");
}
},
error:function(data){
alert("数据加载异常!");
}
});
}
ajax要么用responsebody(自动转化成json),要么用response.getWrite().write()(可以是string,也可以是html(页面局部整个html难拼接))
也可直接return “字符串”,或页面跳转
js中要能回调到需要写对接收格式
=====================================================================================================
response.getWrite().write() (字符)返回和return (页面跳转,字符)在一个方法中可以混用
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
@RequestMapping(value = "/chat/offer/record/{conobjKey}/{ownerKey}/{tradeCustomerKey}/{urlCurrentUserKey}", method = RequestMethod.GET)
public String TbConOrdPriceGetRecord(@RequestParam(value="cx", required=false) String cx,HttpSession session, HttpServletRequest request, HttpServletResponse response, @PathVariable String conobjKey,
@PathVariable String ownerKey, @PathVariable String tradeCustomerKey, @PathVariable String urlCurrentUserKey, Model model)
throws EsteelException, IOException {
if (conobjKey==null || ownerKey==null || tradeCustomerKey==null || urlCurrentUserKey==null || conobjKey.equals("") || ownerKey.equals("") || tradeCustomerKey.equals("") || urlCurrentUserKey.equals("")) {
writeToResponse(response, "invalid key");
return null;
} else {
/* 获取当前用户的key */
String currentuserKey = getCurrentUserKey(request, session);
if (!currentuserKey.equals(urlCurrentUserKey)) {
currentuserKey = urlCurrentUserKey;
}
if (!currentuserKey.equals(ownerKey) && !currentuserKey.equals(tradeCustomerKey)) {
/* 如果当前用户不是主人或者客户,不允许查看 */
writeToResponse(response, "access denied");
return null;
} else {
Map<String,Object> pn = new HashMap<String,Object>();
pn.put("objKey", conobjKey);
Map ren= tbConObjService.getConObjByKeynew(pn);
model.addAttribute("dataMap", ren);
/* if(ren.get("CUSTOMER_KEY").toString().equals(currentuserKey)){
}else{}*/
String MEASURE_MODE= (String) ren.get("MEASURE_MODE");
int wareKindKey= Integer.valueOf(ren.get("WAREKIND_KEY")+"");
String PRICE_MODEL= (String) ren.get("PRICE_MODEL");
String currency_type= (String) ren.get("CURRENCY_TYPE");
String type="";
Map ycLsPara = new HashMap<String,Object>();
ycLsPara.put("conobj_key", conobjKey);
List list = tbConObjService.getYCDHList(ycLsPara);
if (ren.get("BAIL_TYPE").equals("A")){
model.addAttribute("XUNPANTYPE", "No");
}else if ((ren.get("PACK_NAME") == null) || (!ren.get("PACK_NAME").equals("卷"))) {
model.addAttribute("XUNPANTYPE", "No");
}else {
Map ormx = new HashMap<String,Object>();
ormx.put("CONOBJ_KEY", conobjKey);
ormx.put("LIST_STATUS", "A");
List<Map> conObjHuoWuListMap = tbConObjService.getJZMX1(ormx);
model.addAttribute("conObjHuoWuListMap", conObjHuoWuListMap);
model.addAttribute("XUNPANTYPE", "HuoWu");
}
Map paramPz = new HashMap<String,Object>();
paramPz.put("CONOBJ_KEY", conobjKey);
paramPz.put("CUSTOMER_KEY", currentuserKey);
paramPz.put("ORDER_STATUS", "A");
paramPz.put("ORD_KEY", null);
List<Map> conOrdMap= tbConObjService.getConOrdByCustomerKey(paramPz);
if (conOrdMap != null && conOrdMap.size()>0) {
model.addAttribute("conOrdMap", conOrdMap.get(0));
}else{
model.addAttribute("conOrdMap", null);
}
if (conOrdMap != null && conOrdMap.size()>0) {
Map ormx = new HashMap<String,Object>();
ormx.put("ORD_KEY", Integer.valueOf(conOrdMap.get(0).get("ORD_KEY")+""));
ormx.put("ORDPRICE_NO", null);
ormx.put("CUSTOMER_KEY", null);
ormx.put("ORDPRICE_MAN", "A");
tbConObjService.updateConOrdPriceIS_LOOK(ormx);
}
Map corprspara = new HashMap<String,Object>();
corprspara.put("CONOBJ_KEY", conobjKey);
corprspara.put("CUSTOMER_KEY", tradeCustomerKey);//询盘
corprspara.put("ORDPRICE_MAN", null);
List<Map> yjList= tbConObjService.getConOrdPriceList(corprspara);
model.addAttribute("yjList", yjList);
if("Y".equals(ren.get("IS_MULTIWARE"))){
Map paramPzOrdKey = new HashMap<String,Object>();
paramPzOrdKey.put("CONOBJ_KEY", conobjKey);
paramPzOrdKey.put("CUSTOMER_KEY", tradeCustomerKey);
paramPzOrdKey.put("ORDER_STATUS", "D");
paramPzOrdKey.put("ORD_KEY", cx);
List<Map> conOrdMapOrdKey=null;
if(cx==null||"".equals(cx)){
conOrdMapOrdKey=null;
}else{
conOrdMapOrdKey= tbConObjService.getConOrdByCustomerKey(paramPzOrdKey);
}
model.addAttribute("conOrdMapOrdKey", conOrdMapOrdKey);
if ((yjList != null) && (yjList.size() > 0)){
boolean first = true;
for (int i = 0; i < yjList.size(); i++){
Map map = (Map)yjList.get(i);
if ("Y".equals(map.get("IS_MULTIWARE"))){
Map prsMX = new HashMap<String,Object>();
prsMX.put("ord_key", map.get("ORD_KEY"));
prsMX.put("ordprice_no", map.get("ORDPRICE_NO"));
map.put("MX", tbConObjService.getConOrdPriceMX(prsMX));
if (("B".equals(map.get("ORDPRICE_MAN"))) && (first)) {
first = false;
model.addAttribute("conOrdPriceLastObjectMap", tbConObjService.getConOrdPriceMX(prsMX));
}
}
}
}
TbConOrd tbConOrdNew = new TbConOrd();
tbConOrdNew.setOrdKey(cx);
TbConOrd tbConOrdNew2 = null;
if(cx!=null&&!"".equals(cx)){
tbConOrdNew2 = tbConOrdService.getTbConOrdByObj(tbConOrdNew);
}
if(tbConOrdNew2!=null){
model.addAttribute("ordSta", tbConOrdNew2.getOrderStatus());
}else{
model.addAttribute("ordSta", "");
}
if(ren.get("CUSTOMER_KEY").toString().equals(currentuserKey)){
return "/chat/offer/ySaleCDHDickerList";
}else{
return "/chat/offer/yCDHDickerList";
}
}else{
TbConObj tbConObj = tbConObjService.getTbConObjById(conobjKey);
List<TbConOrdVo> tbConOrdVoList = tbConOrdService.getTbConOrdVoList(conobjKey, tradeCustomerKey);
String strJson = "({";
strJson += "\"chatRecord\":[";
int k = 0;
String highPrice = "1999999999";
String lowPrice = "0";
for (TbConOrdVo tbConOrdVo1 : tbConOrdVoList) {
/* 循环得到最高价和最低价 */
if (tbConOrdVo1.getOrdpriceMan() != null) {
if (tbConOrdVo1.getOrdpriceMan().equals("B")) {
/* 不是是发起方 */
if (tbConOrdVo1.getContradeType().equals("A")) {
/* 是卖单 */
if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
lowPrice = tbConOrdVo1.getOrderPrice();
}
} else {
/* 是买单 */
if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
highPrice = tbConOrdVo1.getOrderPrice();
}
}
} else {
/* 是发起方 */
if (tbConOrdVo1.getContradeType().equals("A")) {
/* 是卖单 */
if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
highPrice = tbConOrdVo1.getOrderPrice();
}
} else {
/* 是买单 */
if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
lowPrice = tbConOrdVo1.getOrderPrice();
}
}
}
} else {
/* 不是是发起方 */
if (tbConOrdVo1.getContradeType().equals("A")) {
/* 是卖单 */
if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
lowPrice = tbConOrdVo1.getOrderPrice();
}
} else {
/* 是买单 */
if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {
highPrice = tbConOrdVo1.getOrderPrice();
}
}
}
k = k + 1;
strJson += "{";
String msgText = tbConOrdVo1.getMsgText();
if (null == msgText || msgText.contains("请录入您的议价留言,最大为300个字符!按Ctrl+Enter提交!")) {
msgText = "";
}
/* 替换掉换行符,否则会报错 */
msgText = msgText.replaceAll("\n", "");
int chatChoice = 0;
int isdlfs=0;
if(tbConObj.getCustomerKey().equals(currentuserKey)){
isdlfs=1;
}
if (tbConOrdVo1.getOrdpriceMan() != null) {
if (tbConOrdVo1.getOrdpriceMan().equals("B")) {
chatChoice = 2;
int flag =0;
if(tbConObj.getCustomerKey().equals(currentuserKey)){
flag=1;
}
/* 不是是发起方 */
strJson += "\"chatChoice\":\"2\","+"\"isDlFQ\":\""+flag+"\","+"\"isdlfs\":\""+isdlfs+"\",";
} else {
/* 是发起方 */
chatChoice = 1;
int flag =0;
if(tbConObj.getCustomerKey().equals(currentuserKey)){
flag=1;
}
strJson += "\"chatChoice\":\"1\","+"\"isDlFQ\":\""+flag+"\","+"\"isdlfs\":\""+isdlfs+"\",";
}
} else {
chatChoice = 1;
int flag =0;
if(tbConObj.getCustomerKey().equals(currentuserKey)){
flag=1;
}
strJson += "\"chatChoice\":\"1\","+"\"isDlFQ\":\""+flag+"\","+"\"isdlfs\":\""+isdlfs+"\",";
}
if (tbConObj.getAnonymMark().equals("B")) {
strJson += "\"chatName\":\"***\",";
} else {
/*
* 当currentuserKey eq
* tbConObj.getCustomerKey(),说明当前是主人在浏览
*/
/*
* 当currentuserKey eq
* tbConOrdVo1.getCustomerKey(),说明是客人在浏览
*/
if (chatChoice == 1 && currentuserKey.equals(tbConObj.getCustomerKey())) {
strJson += "\"chatName\":\"我\",";
} else if (chatChoice == 2 && currentuserKey.equals(tbConOrdVo1.getCustomerKey())) {
strJson += "\"chatName\":\"我\",";
} else {
if(chatChoice == 1){
strJson += "\"chatName\":\"" + ren.get("CUSTOMER_NAME") + "\",";//tbConOrdVo1.getCustomerName()
}else{
strJson += "\"chatName\":\"" + tbConOrdVo1.getCustomerName() + "\",";//tbConOrdVo1.getCustomerName()
}
}
}
strJson += "\"chatPrice\":\"" + tbConOrdVo1.getNewPrice() + "\",";
if (tbConObj.getCurrencyType().equals("A")) {
strJson += "\"chatCurrency\":\"元\",";
} else if (tbConObj.getCurrencyType().equals("B")) {
strJson += "\"chatCurrency\":\"美元\",";
}
strJson += "\"chatNumUnit\":\"" + tbConObj.getNumUnit() + "\",";
strJson += "\"chatNum\":\"" + tbConOrdVo1.getNewNum() + "\",";//tbConOrdVo1.getOrderNum()
strJson += "\"objKey\":\"" + tbConOrdVo1.getConobjKey()+ "\",";
strJson += "\"ordKey\":\"" + tbConOrdVo1.getOrdKey() + "\",";
strJson += "\"ordPriceNo\":\"" + tbConOrdVo1.getOrdpriceNo() + "\",";
strJson += "\"contradeKind\":\"" + tbConObj.getContradeKind() + "\",";
strJson += "\"ordKey\":\"" + tbConOrdVo1.getOrdKey() + "\",";
strJson += "\"chatMsgText\":\"" + msgText + "\"}";
if (k < tbConOrdVoList.size()) {
strJson += ",";
}
}
TbConOrd tbConOrdNew = new TbConOrd();
tbConOrdNew.setOrdKey(cx);
TbConOrd tbConOrdNew2 = null;
if(cx!=null&&!"".equals(cx)){
tbConOrdNew2 = tbConOrdService.getTbConOrdByObj(tbConOrdNew);
}
strJson += "],";
strJson += "\"highPrice\":\"" + highPrice + "\",";
if(tbConOrdNew2!=null){
strJson += "\"ordSta\":\"" + tbConOrdNew2.getOrderStatus() + "\",";
}else{
strJson += "\"ordSta\":\"\",";
}
strJson += "\"lowPrice\":\"" + lowPrice + "\"";
strJson += "})";
writeToResponse(response, strJson);
return null;
}
}
}
}