


How to solve the problem that SpringBoot2's PUT request cannot receive parameters
HiddenHttpMethodFilter
The form form in html only supports GET and POST requests, but methods such as DELETE and PUT are not supported. Spring3 has added a filter that can The request is converted to a standard http method, allowing GET, POST, PUT and DELETE requests to be supported.
@Bean public FilterRegistrationBean<HiddenHttpMethodFilter> testFilterRegistration3() { FilterRegistrationBean<HiddenHttpMethodFilter> registration = new FilterRegistrationBean<HiddenHttpMethodFilter>(); registration.setFilter(new HiddenHttpMethodFilter());//添加过滤器 registration.addUrlPatterns("/*");//设置过滤路径,/*所有路径 registration.setName("HiddenHttpMethodFilter");//设置优先级 registration.setOrder(2);//设置优先级 return registration; }
Set the method to Post in the form form of the page, and add a hidden field as follows:
<input type="hidden" name="_method" value="put" />
View HiddenHttpMethodFilter source code
String paramValue = request.getParameter(methodParam); if("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) { String method = paramValue.toUpperCase(Locale.ENGLISH); HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method); filterChain.doFilter(wrapper, response); } else { filterChain.doFilter(request, response); } }
As can be seen from the source code, filter Only the Post method is filtered, and a hidden field with the parameter name _method needs to be added. You can also set other parameter names. For example, if you want to set it to _method_, you can set the initialization parameters in the HiddenHttpMethodFilter configuration class: put (methodParam, "_method_" )
HttpPutFormContentFilter
It can be seen from HiddenHttpMethodFilter that the method value of the form in html can only be post or get. We can get the put form through HiddenHttpMethodFilter. Parameter key-value pairs, and there is another way to get the parameter key-value pairs of the put form in Spring3, which is to use the HttpPutFormContentFilter filter.
@Bean public FilterRegistrationBean<HttpPutFormContentFilter> testFilterRegistration2() { FilterRegistrationBean<HttpPutFormContentFilter> registration = new FilterRegistrationBean<HttpPutFormContentFilter>(); registration.setFilter(new HttpPutFormContentFilter());//添加过滤器 registration.addUrlPatterns("/*");//设置过滤路径,/*所有路径 registration.setName("HttpPutFormContentFilter");//设置优先级 registration.setOrder(2);//设置优先级 return registration; }
The function of the HttpPutFormContentFilter filter is to obtain the value of the put form and pass it to the method in the Controller marked with the method RequestMethod.put.
Different from HiddenHttpMethodFilter, there is no need to add a hidden field with the parameter name _method in the form, and the method does not have to be post, it can be written directly as put, but this filter can only accept the enctype value as application/x -www-form-urlencoded form, that is to say, when using this filter, the code of the form form must be as follows:
<form action="" method="put" enctype="application/x-www-form-urlencoded"> ...... </form>
In addition, after testing, the json data is also ok,enctype=”application/json”It’s also ok
The above is the detailed content of How to solve the problem that SpringBoot2's PUT request cannot receive parameters. For more information, please follow other related articles on the PHP Chinese website!

JVM'sperformanceiscompetitivewithotherruntimes,offeringabalanceofspeed,safety,andproductivity.1)JVMusesJITcompilationfordynamicoptimizations.2)C offersnativeperformancebutlacksJVM'ssafetyfeatures.3)Pythonisslowerbuteasiertouse.4)JavaScript'sJITisles

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunonanyplatformwithaJVM.1)Codeiscompiledintobytecode,notmachine-specificcode.2)BytecodeisinterpretedbytheJVM,enablingcross-platformexecution.3)Developersshouldtestacross

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java implementation "write once, run everywhere" is compiled into bytecode and run on a Java virtual machine (JVM). 1) Write Java code and compile it into bytecode. 2) Bytecode runs on any platform with JVM installed. 3) Use Java native interface (JNI) to handle platform-specific functions. Despite challenges such as JVM consistency and the use of platform-specific libraries, WORA greatly improves development efficiency and deployment flexibility.

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunondifferentoperatingsystemswithoutmodification.TheJVMcompilesJavacodeintoplatform-independentbytecode,whichittheninterpretsandexecutesonthespecificOS,abstractingawayOS

Javaispowerfulduetoitsplatformindependence,object-orientednature,richstandardlibrary,performancecapabilities,andstrongsecurityfeatures.1)PlatformindependenceallowsapplicationstorunonanydevicesupportingJava.2)Object-orientedprogrammingpromotesmodulara

The top Java functions include: 1) object-oriented programming, supporting polymorphism, improving code flexibility and maintainability; 2) exception handling mechanism, improving code robustness through try-catch-finally blocks; 3) garbage collection, simplifying memory management; 4) generics, enhancing type safety; 5) ambda expressions and functional programming to make the code more concise and expressive; 6) rich standard libraries, providing optimized data structures and algorithms.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
