Biswajit
Biswajit

Reputation: 15

How to send one of the json parameter of a request body through url and rest through body of postman for @Postmapping

I have a class:

public class SubMdl {

    private Integer Id;

    @NotEmpty
    private String mssd;
        
    private String name;
    
    private String location;

//constructor,getters,setters

}

While doing @Postmapping can we send mssd in the url and rest of the data in the json body in the postman combined?

If possible then what will be written in controller class as @RequestBody in the controller will expect whole data and definitely considering @NotEmpty.

Is there any solution available?

Upvotes: 0

Views: 904

Answers (1)

Nishant Bhardwaz
Nishant Bhardwaz

Reputation: 1001

You can send mssd as PathVariable or RequestParam and rest of the parameter as ReqeustBody as below.

@PostMapping(value = "/{id}")
    public String samplePost(@PathVariable("mssd") String mssd, @RequestBody SubMdlChild payload){
       return <your-service-call>;
    }

UPDATE: In the RequestBody, I have taken a sample class name SubMdlChild which will not contain the mssd as per your requirement.

Upvotes: 1

Related Questions