I migrated a Spring 4.1 application (running I JBoss) to SpringBoot 1.5 (Spring 4.3.7), and after that, all our MVC Controllers with String parameters always receive null values when called.
The only way I could get the parameter value set was to replace String with StringBuilder.
An example, not working anymore:
@RequestMapping(value = "/updateTime", method = RequestMethod.POST)
public String updateTime(@RequestParam(value="time") String time) {
// time is null in SpringBoot
}
Working (StringBuffer instead of String:
@RequestMapping(value = "/updateTime", method = RequestMethod.POST)
public String updateTime(@RequestParam(value="time") StringBuffer time) {
// time has expected value
}
HTML:
<form name="updateTime" action="updateTime.html" method="post">
Time: <input type="text" name="time" placeholder="YYYY-MM-DD HH:mm" value="${time}"/> <br/>
<input type="submit" name="action" value=" Update "/>
</form>
Even when String parameters in the controller are compounded into a request object I get this behaviour.
Am I doing something wrong here?
INFO : Spring Works with HTML name attributes. You should have the same name and RequestParam value. Note : in the HTML form action it's better to have the same as the RequestMapping value also. Try this :
<form name="updateTime" action="/updateTime" method="post">
Time: <input type="text" name="time" placeholder="YYYY-MM-DD HH:mm" value="${time}"/> <br/>
<input type="submit" name="action" value=" Update "/>
</form>
@RequestMapping(value = "/updateTime", method = RequestMethod.POST)
public String updateTime(@RequestParam(value="time") String time) {
// time is null in SpringBoot
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.