Project scenario:
Due to environmental problems, the server is only allowed to use the post and get methods to call the interface. The delete interface written using the post method can be called locally, but an error is reported in the server.
Problem description
Use the post method for logical deletion and error reporting, and use @pathvariable
to obtain the front-end transmission parameters:
@PostMapping("/delete/{userGroupIds}")
public ResponseBean<Object> deleteUserGroup(@PathVariable("userGroupIds") String userGroupIds){
return userGroupService.deleteUserGroup(userGroupIds);
}
When using postman to call the server interface, the following error messages appear:
The front-end page calls the interface and reports the following error, cross domain:
Cause analysis:
The post method needs to use @Rquestbody
to obtain parameters. This problem occurs when null is passed. The specific details were not clarified.
Solution:
Change the @pathvariable
method to @rquestbody
.
@PostMapping("/delete")
public ResponseBean<Object> deleteUserGroup(@RequestBody UserGroupIdDTO userGroupIds){
return userGroupService.deleteUserGroup(userGroupIds);
}
The parameters in UserGroupIdDTO are as follows:
@Data
public class UserGroupIdDTO {
private String userGroupId;
}
Read More:
- Asynchronous processing of HTTP request by Java_ Method 1: through callable
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- Abstract method and static method of java interface
- JAVA: How to Read JSON Format Data (Web Game Development)
- feign.codec.EncodeException: Type definition error: [simple type, class java.util.Collections$3]
- Problems and causes of Java’s main function format (public static void main (string args()))
- Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl
- I/O error while reading input message; nested exception is java.io.IOException: Stream closed
- How to convert a Java string into a number (stringtonumber)
- How to Converte Java objects to jsonnode in Jackson (Four Methods)
- [Solved] Java 9 reflection error: java.lang.reflect.InaccessibleObjectException
- How to Solve JAR pack error: Error resolving template [/userInfo], template might not exist or might not be accessib
- JAVA: How to Use Minio to upload pictures
- How to Solve JUnit Debugging initializationerror ERROR
- Ternary operator in Java?: error: not a statement
- [Solved] JSON parse error: Cannot deserialize instance of `java.util.ArrayList<..> out of START_OBJECT token;
- Explicit and implicit conversion of Java data type
- SpringMVc @RequestMapping url of regular expression pattern
- Xdoc generates API documents based on Java annotations
- Comparison method violates its general contract [How to Solve]