java - Get form's multiple inputs with the same name in spring mvc -
i have input fields in jsp page, , fields can dynamically created or removed. have map input fields spring mvc's @modelattributes. not know how map input fields.
i want submit form composed of:
<form enctype="multipart/form-data"> <!-- code omitted --> <div> <input type="text" name="content"> <input type="file" name="file"> </div> <div> <input type="text" name="content"> <input type="file" name="file"> </div> <div> <input type="text" name="content"> <input type="file" name="file"> </div> </form>
and fields should guided java classe(@modelattribute):
package com.musicovery12.cookingstep.web.command; import java.util.arrays; import java.util.list; public class addrecipecommand { private string mainimageurl; private string foodname; private string kcal; private string ingredients; private string fooddescription; // not know how map field. private list<recipestep> recipesteps; private string videourl; public string getmainimageurl() { return mainimageurl; } public void setmainimageurl(string mainimageurl) { this.mainimageurl = mainimageurl; } public string getfoodname() { return foodname; } public void setfoodname(string foodname) { this.foodname = foodname; } public string getkcal() { return kcal; } public void setkcal(string kcal) { this.kcal = kcal; } public string getingredients() { return ingredients; } public void setingredients(string ingredients) { this.ingredients = ingredients; } public string getfooddescription() { return fooddescription; } public void setfooddescription(string fooddescription) { this.fooddescription = fooddescription; } public list<recipestep> getrecipesteps() { return recipesteps; } public void setrecipesteps(list<recipestep> recipesteps) { this.recipesteps = recipesteps; } public string getvideourl() { return videourl; } public void setvideourl(string videourl) { this.videourl = videourl; } @override public string tostring() { return "addrecipecommand [mainimageurl=" + mainimageurl + ", foodname=" + foodname + ", kcal=" + kcal + ", ingredients=" + ingredients + ", fooddescription=" + fooddescription + ", recipesteps=" + recipesteps + ", videourl=" + videourl + "]"; } }
that command class has property not primitive type. it's recipestep:
package com.musicovery12.cookingstep.web.command; import org.springframework.web.multipart.multipartfile; public class recipestep { private string content; private multipartfile image; public recipestep() {} public string getcontent() { return content; } public void setcontent(string content) { this.content = content; } public multipartfile getimage() { return image; } public void setimage(multipartfile image) { this.image = image; } @override public string tostring() { return "recipestep [content=" + content + ", image=" + image + "]"; } }
so question is, how map form's input fields above java class? possible changing name of input fields? then, how?
public class multiplefileuploadform {
private list<multipartfile> files; public list<multipartfile> getfiles() { return files; } public void setfiles(list<multipartfile> files) { this.files = files; }
}
public @responsebody string handlefileupload(@modelattribute("multiplefileuploadform") multiplefileuploadform multiplefileuploadform){
}
add @modelattribute in controller
wiki
Comments
Post a Comment