Reputation: 864
I'm trying to have Spring boot convert my form data into an Object representation (ExampleInputForm
), but for some reason it doesn't seem to bind (emailName
is always null
). Am I missing something here?
public class ExampleInputForm {
@NotNull
public String emailName;
public ExampleInputForm() {
super();
}
@Override
public String toString() {
return "ExampleInputForm{" +
"emailName='" + emailName + '\'' +
'}';
}
}
@Controller
class MyController {
@RequestMapping(method = RequestMethod.POST, value="/save")
@ResponseBody
public Map<String, String> saveBrands(@Valid ExampleInputForm form, BindingResult bindingResult) {
LOG.info("Saving brands: " + form);
return ImmutableMap.of(
"emailName", form.emailName,
);
}
}
<div class="container">
<div class="row text-center">
<form name="input" action="/save" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" name="emailName">
</div>
<input type="submit" value="Save" class="btn btn-default" />
</form>
</div>
</div>
Upvotes: 1
Views: 708
Reputation: 116
You need to add getter/setter for your emailName attribute to your ExampleInputForm class.
Upvotes: 3