Spring mvc parameter complex mixed transfer method, mixed return method

============================================================================

 

Spring mvc parameter complex mixed transfer method, mixed return method:

When passing the entity of the list, if you also pass other single attributes, these single attributes should be placed in the requestHeader,

Similar image streams are placed in the requestbody (generally httpclient tool side), and the background is also taken from the 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){///parameter head

        xhr.setRequestHeader('id', id);//Note that different browsers will have problems with empty values ​​in this header parameter, add required=false in the background

        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("The member number you entered does not exist!");

        }

       

        },

        error:function(data){

        alert("Data loading exception!");

       

        }

    }); 

 

    }

 

 

Ajax can either use responsebody (automatically converted to json), or use response.getWrite().write() (can be string or html (the whole html part of the page is difficult to splicing))

You can also directly return "string", or page jump

 

js to be able to call back to the need to write the receiving format

 

=====================================================================================================

 

response.getWrite().write() (character) return and return (page jump, character) can be mixed in one method

 

        @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,

AthPathVariable String ownerKey, athPathVariable String tradeCustomerKey, athPathVariable 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 {

/* Get the key of the current user */

String currentuserKey = getCurrentUserKey(request, session);

if (!currentuserKey.equals(urlCurrentUserKey)) {

currentuserKey = urlCurrentUserKey;

}

if (!currentuserKey.equals(ownerKey) && !currentuserKey.equals(tradeCustomerKey)) {

/* If the current user is not the owner or client, view is not allowed */

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) {

/* Loop to get the highest and lowest prices */

if (tbConOrdVo1.getOrdpriceMan() != null) {

if (tbConOrdVo1.getOrdpriceMan().equals("B")) {

/* Not the initiator */

if (tbConOrdVo1.getContradeType().equals("A")) {

/* is a sell order */

if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

lowPrice = tbConOrdVo1.getOrderPrice();

}

} else {

/* is a buy order */

if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

highPrice = tbConOrdVo1.getOrderPrice();

}

}

} else {

 

 

/* is the initiator */

if (tbConOrdVo1.getContradeType().equals("A")) {

/* is a sell order */

if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

highPrice = tbConOrdVo1.getOrderPrice();

}

} else {

/* is a buy order */

if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

lowPrice = tbConOrdVo1.getOrderPrice();

}

}

}

} else {

/* Not the initiator */

if (tbConOrdVo1.getContradeType().equals("A")) {

/* is a sell order */

if (Double.parseDouble(lowPrice) < Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

lowPrice = tbConOrdVo1.getOrderPrice();

}

} else {

/* is a buy order */

if (Double.parseDouble(highPrice) > Double.parseDouble(tbConOrdVo1.getOrderPrice())) {

highPrice = tbConOrdVo1.getOrderPrice();

}

}

}

k = k + 1;

strJson += "{";

String msgText = tbConOrdVo1.getMsgText();

if (null == msgText || msgText.contains("Please enter your negotiation message, the maximum length is 300 characters! Press Ctrl+Enter to submit!")) {

msgText = "";

}

/* replace the newline character, otherwise an error will be reported */

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;

}

/* Not the initiator */

strJson += "\"chatChoice\":\"2\","+"\"isDlFQ\":\""+flag+"\","+"\"isdlfs\":\""+isdlfs+"\",";

 

} else {

 

/* is the initiator */

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(), indicating that the owner is currently browsing

*/

/*

* 当currentuserKey eq

* tbConOrdVo1.getCustomerKey(), indicating that the guest is browsing

*/

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;

}

}

 

}

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441687&siteId=291194637