用springboot时,遇到了一些参数传递问题。
1、要传递一组MappingDto,实体对象如下
public class MappingDto {
private Mapping mapping;
private String verifyFlag;
}
public class Mapping {
private String mappingid;
private String standardname;
private String realname;
private String sheetid;
private String serialno;
}
(1)增加一个MappingDtoList对象,用户传递
public class MappingDtoList {
private List<MappingDto> mappingDtoList = new ArrayList<MappingDto>();
}
(2)重点在前端的写法:
<c:forEach items="${FIND_MAPPING_BY_SHEETID }" var="each" varStatus="status">
<c:if test="${status.index%2==0}"><div class="form-group-left"></c:if>
<c:if test="${status.index%2!=0}"><div class="form-group-right"></c:if>
<label class="mylabel sr-only" for="sel_search_orderstatus1" id="label${status.index }">${each.realname }</label>
<!-- form提交时需要的参数 -->
<input type="hidden" name="mappingDtoList[${status.index}].mapping.mappingid" value="${each.mappingid }" />
<input type="hidden" name="mappingDtoList[${status.index}].mapping.realname" value="${each.realname }" />
<input type="hidden" name="mappingDtoList[${status.index}].mapping.sheetid" value="${each.sheetid }" />
<input type="hidden" name="mappingDtoList[${status.index}].verifyFlag" id="verifyFlag${status.index}" />
<div class="form-control select">
<select name="mappingDtoList[${status.index}].mapping.standardname" id="selectStandradName${status.index }"
style="width:150px" onchange="changeCss('label${status.index }', 'selectStandradName${status.index }');"
required >
省略.......
</c:forEach>
(3)后台接收
@RequestMapping(value = "/updateStandradNameByMappingId")
public String updateStandradNameByMappingId(MappingDtoList mappingDtoList, Map<String, Object> model) {
logger.info("需要插入的mappingDtoList:" + mappingDtoList);
......
}
重点就是把list封装成对象,再传递这个对象即可。
2、传递临时对象,用model返回
3、传递跟用户相关的,需要反复使用的对象,用session传递。useid+对象名,用于区分不同用户存储的对象
4、传递用于模态框中展示的提示信息,用枚举类型PageCodeEnum封装
public enum PageCodeEnum {
EDITCHANGEDMAPPING(1000, "映射关系发生变化,是否需要修改?"),
EDITEXISTEDMAPPING(1011, "映射关系已经存在,是否需要修改?"),
FILEISNULL(1001, "上传失败,文件是空的."),
FILEILLEGAL(1002, "上传的文件格式不合法,请重新上传"),
EDITMAPPINGVALUE(1003, "上次上传和本次上传映射关系不一致,是否需要修改?"),
INSERTFAILED(1004, "插入映射失败,请重新操作"),
INSERTMAPPINGSUCCESS(1005, "插入映射成功"),
INSERTDATASUCCESS(1006, "插入数据成功"),
INSERTDATAFAIL(1007, "插入数据失败,请重新操作"),
UPLOADFILEFIRST(1008, "需求列表为空,请先上传文件"),
UPLOADFILEFIRST2(1009, "当前没有生成汇总表,请先上传文件"),
FILENAMEISWRONG(1010, "上传的文件名不对,请重新上传"),
USERNAMEPASSWORDWRONG(2000, "用户名与密码不匹配,请重新输入"),
UPDATEPASSWORDSUCCEED(2001, "密码修改成功,请重新登录"),
UPDATEPASSWORDFAILED(2002, "密码修改失败,请重新操作"),
private Integer code;
private String msg;
public static final String KEY = "pageCode";
PageCodeEnum(Integer code,String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
网友评论