Spring: How to get parameters from POST body?

前端 未结 6 935
庸人自扰
庸人自扰 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:55

    You will need these imports...

    import javax.servlet.*;
    import javax.servlet.http.*;
    

    And, if you're using Maven, you'll also need this in the dependencies block of the pom.xml file in your project's base directory.

    
        javax.servlet
        javax.servlet-api
        3.0.1
        provided
    
    

    Then the above-listed fix by Jason will work:

    @ResponseBody
        public ResponseEntity saveData(HttpServletRequest request,
            HttpServletResponse response, Model model){
            String jsonString = request.getParameter("json");
        }
    

提交回复
热议问题