Spring MVC ModelAttribute Fields Are Null Instead of Form Input Values

做~自己de王妃 提交于 2019-12-04 04:35:41

So I think I found the perp!

This lil' guy right here in the POST AJAX call:

contentType: "application/json",

I was originally sending JSON to my controller, then I learned that Spring MVC had that nifty ModelAttribute annotation, so I wouldn't have to worry about converting to/from JSON during my POST. Unfortunately, I didn't think to remove that contentType line, and one would think that it would throw an error or something with it still in there... apparently not. Just NULL values in the binding and hours of fruitless debugging...

After I removed that line, I started getting data in the CardRequest attributes instead of NULLs!

HVT7

Try to put the following code in the aplication-context.xml. This could be the solution if you are having your form encType='multipart/form-data'.

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000"/>
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!