springmvc接受form表单提交多个name相同的字段参数
发布时间:2018-08-29 19:35,
浏览次数:452
, 标签:
springmvc
form
name
本人菜鸟一枚,写博客是为了记录自己在开发过程中遇到的问题,欢迎大家交流留言,勿喷,谢谢。
开发环境:ssm框架+jdk1.7+myeclipse+tomcat+bootstrap;
需求说明:用户根据实际情况,可以添加多条数据 提交后台;
form表单我就不截图了,下面是动态添加div的代码;
JSP代码部分
function() { var hrml = ”
class=’col-sm-2 control-label’>
class=’form-control’ rows=’3′ name=’task_jdxgzrrms’
id=’task_jdxgzrrms’>
” + ”
class=’col-sm-2 control-label’>到期提醒
type=’text’ class=’form-control datetimepicker’ id=’task_txkssj’
name=’task_txkssj’>
至” +
”
id=’task_txjssj’ name=’task_txjssj’>
” $(“#zdwf_sztx”).append(hrml) }
Java代码部分
@RequestMapping(value = “save”, method = RequestMethod.POST) public String
task_informations( HttpServletRequest request, @RequestParam(value =
“task_file”) MultipartFile file, @RequestParam(value = “task_jdxgzrrms”,
required = false) String[] task_jdxgzrrms, @RequestParam(value = “task_txkssj”,
required = false) String[] task_txkssj, @RequestParam(value = “task_txjssj”,
required = false) String[] task_txjssj, RedirectAttributes redirectAttributes)
{ if (task_jdxgzrrms != null && task_txkssj != null && task_txjssj != null) {
periodicity pd = new periodicity(); for (int i = 0, len =
task_jdxgzrrms.length; i < len; i++) {
pd.setWork_description(task_jdxgzrrms[i]);
pd.setTermination_date(task_txjssj[i]); pd.setStarting_date(task_txkssj[i]);
taskservice.save_periodicity(pd); } }; addMessage(redirectAttributes,
“信息保存成功”); return “redirect:/task/index”; }