Spring: How to get parameters from POST body?

前端 未结 6 947
庸人自扰
庸人自扰 2020-12-29 06:00

Web-service using spring in which I have to get the params from the body of my post request? The content of the body is like:-

source=”mysource”

&json=
         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 06:58

    You can bind the json to a POJO using MappingJacksonHttpMessageConverter . Thus your controller signature can read :-

      public ResponseEntity saveData(@RequestBody RequestDTO req) 
    

    Where RequestDTO needs to be a bean appropriately annotated to work with jackson serializing/deserializing. Your *-servlet.xml file should have the Jackson message converter registered in RequestMappingHandler as follows :-

      
        
    
      
    
    
    

提交回复
热议问题