简体   繁体   中英

Java - How to insert data using postman

My code is running perfect but at the postman side showing error

"The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."

while posted data is coming in restController , serviceImpl and in Studentimpl too.

My restController Is

        @RequestMapping(value="save",method=RequestMethod.POST,produces="application/json")

        GetStudentSaveResponse saveResponse(@RequestBody GetStudentSaveRequest saveRequest)
        {
            System.out.println(saveRequest.getName());
            System.out.println(saveRequest.getAddress());
            return serviceIntf.saveResponse(saveRequest);
        }
         RestImpl is
         @Override
        public GetStudentSaveResponse saveResponse(GetStudentSaveRequest saveRequest) {
                GetStudentSaveResponse saveResponse = new GetStudentSaveResponse();
                studentIntf.SaveStudent(saveRequest.getName(), saveRequest.getAddress());           
                System.out.println("SERVICE"+saveRequest.getName());
                return saveResponse;
            }

Implementation class is:

public void SaveStudent(String name, String address) {
    try
    {
        java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
        con=jdbctemplate.getDataSource().getConnection();

        CallableStatement call = con.prepareCall("{Student_pro(?,?,?,?,?)}");
        call.setString(1, "insertStudent");
        call.setInt(2, 0);
        call.setString(3, name);
        call.setString(4, address);
        call.setDate(5, date);

        System.out.println(name);
        System.out.println(address);

    }catch(Exception e){e.printStackTrace();}
}

Make sure your Controller class is annotated with the following

@Controller
@EnableWebMvc 

You are getting HTTP 406, which indicates the media type is incorrect. Set the content type as application/json as shown below

在此处输入图片说明

Update:

The issue is, if you want to return an Object from your POST method, use ResponseEntity<Object> instead of directly using Object. Hence, in this case you change your return type to ResponseEntity<GetStudentSaveResponse>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM