Spring mvc receives the parameters of the form form in the form of a map:

 

As long as there is @RequestParam Map<String, Object> regUser in @controller; this map will automatically use the name as the key of the map and the corresponding value as the value of the map when the jsp is submitted.

This kind of application is complicated for fields such as registration, but the reusability is not high (this time it is not to create a bo to receive) , and map is used to receive because the parameter pair name after receiving the url with a single parameter is a form temporarily combined by the database,

The domain values ​​in the url can be received. For details, please refer to the subsequent multi-image upload with different names. Even the parameter "=" after the url can also be

don't need to

                param.remove("navTabId");

param.remove("callbackType");

param.remove("menuitemId");

param.put("PROVINCE_AREA_KEY", param.get("provinceAreaKey"));//Replace with database field

param.put("CITY_AREA_KEY", param.get("cityAreaKey"));

param.put("COUNTY_AREA_KEY", param.get("country"));

param.remove("provinceAreaKey");

param.remove("cityAreaKey");

param.remove("country");

param.remove("button2");

 

 

http://www.codes51.com/article/detail_114729.html

 

@RestController

@RequestMapping(value = "/mapParameter/")

public class MapParameter {

 

/**

* Use Map to receive the Form Data or Query String submitted by the front-end. If there are the same parameter names, only the first one will be received.

* @author XuJijun

* @param params

* @return

*/

@RequestMapping(value = "map")

public Map<String, Object> test1(@RequestParam Map<String, Object> params) {

Map<String, Object> resultMap = new HashMap<String, Object>();

resultMap = params;

return resultMap;

}

 

/**

* Use MultiValueMap to receive the Form Data or Query String submitted by the front end, and you can receive the value of the same parameter name into the same list

* @author XuJijun

* @param params

* @return

*/

@RequestMapping(value = "multiValueMap")

public Map<String, List<Object>> test2(@RequestParam MultiValueMap<String, Object> params) {

Map<String, List<Object>> resultMap = new HashMap<>();

resultMap = params;

return resultMap;

}

 

/**

* Use Map to receive the Request Payload in json format submitted by the front end. If there are the same parameter names, only the last one is received

* @author XuJijun

* @param params

* @return

*/

@RequestMapping(value = "jsonParams")

public Map<String, Object> test3(@RequestBody Map<String, Object> params) {

Map<String, Object> resultMap = new HashMap<String, Object>();

resultMap = params;

return resultMap;

}

}

 

 

示例:

 

 

@RequestMapping("/account/tbCusFirmChg/edit")

public String add(@RequestParam(value = "customerKey", required = false) String customerKey,@RequestParam Map<String, Object> regUser,Model model) throws EsteelException {

 

}

form action="<c:url value='/account/tbCusFirmChg/edit?navTabId=userLiNav&callbackType=closeCurrent'/>" method="post" validate="true" onsubmit="return validForm();">

<div style="height: 645px; overflow:auto; ">

    <input type="hidden" name="CUSTOMER_KEY" value="CUSTOMER_KEY">

    <input type="hidden" name="menuitemId" value="menuitemId">

    <fieldset style="margin: auto;">

    <legend>公司信息</legend>

    <dl style="width: 50%;float: left;margin-bottom: 3px;">

    <dt style="float: left;text-align:right;width: 20%; ">会员编码:</dt>

    <dd style="float: left;text-align:left;width: 30%;"><input  name="CUSTOMER_ID" id="regUser_CUSTOMER_ID" class="required  textInput"  value="${CUSTOMER_ID}" maxlength="18" onkeydown="if (event.keyCode==13)event.keyCode=9;"/></dd>

    </dl>

    <dl style="width: 50%;float: left;margin-bottom: 3px;">

    <dt style="float: left;text-align:right;width: 20%;">子账号席位:</dt>

    <dd style="float: left;text-align:left;width: 30%;"><input  name="SET_USER_NUM" id="regUser.SET_USER_NUM" class="input-longer"  value="${voo.SET_USER_NUM}" maxlength="3" /></dd>

    </dl>

    

    <dl style="width: 50%;float: left;margin-bottom: 3px;">

    <dt style="float: left;text-align:right;width: 20%;">公司类型:</dt>

    <dd style="float: left;text-align:left;width: 30%;"> <label id="regUser_COMP_TYPEA" ><input type="radio" id="COMP_TYPEA" name="COMP_TYPE" value="Y" 

    

    <c:if test="${voo.COMP_TYPE=='Y' or voo.COMP_TYPE!='N'}">checked="checked"</c:if> />境内<input type="radio" name="COMP_TYPE" value="N" <c:if test="${voo.COMP_TYPE=='N'}">checked="checked"</c:if> />境外</label></dd>

    </dl>

    <dl style="width: 50%;float: left;margin-bottom: 3px;">

    <dt style="float: left;text-align:right;width: 20%;" ><span id="wmzzmc">外贸资质:</span></dt>

    <dd style="float: left;text-align:left;width: 30%;" ><SPAN id="wmzzxz"><label id="regUser_TRADE_APTA"><input type="radio" id="TRADE_APTA" name="TRADE_APT" value="Y" <c:if test="${voo.tradeApt=='Y' or voo.tradeApt!='N' or voo.COMP_TYPE=='Y'}">checked="checked"</c:if> />具备<input type="radio" name="TRADE_APT" value="N" <c:if test="${voo.tradeApt=='N'}">checked="checked"</c:if> />不具备</label></SPAN></dd>

    </dl>

    </div>

    </form>

 

 

 

Guess you like

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