ModelAttribute for Restful PUT method not populated value ( JSON )

橙三吉。 提交于 2019-12-01 12:52:38
MaximeF

Im replace

@ModelAttribute("positionGPS") PositionGPS positionGPS, @PathVariable Long id, Model model

for

@RequestBody PositionGPS positionGPS, @PathVariable Long id, Model model)

Link help: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-config-enable

and

Spring MVC: Don't deserialize JSON request body

If you're using an HTML form it doesn't support PUT. If you want to support PUT then you need to send the contents of the form serialized with Ajax. With XMLHttpRequest you can use all the major verbs (OPTIONS, GET, POST, PUT, DELETE). If you can't use Ajax the only other option is to tunnel everything through POST for create, update and delete operations.

Add the below filter to your WebApplicationInitializer class or corresponding xml code to web.xml

final FilterRegistration.Dynamic httpMethodFilter = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter());
        httpMethodFilter.addMappingForUrlPatterns(null, true, "/*");

        final FilterRegistration.Dynamic putFormFilter = servletContext.addFilter("httpPutFormContentFilter", new HttpPutFormContentFilter());
        putFormFilter.addMappingForUrlPatterns(null, true, "/*");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!