Reputation: 471
I'm using intelliJIDEA, Here is my controller:
@RequestMapping(value = "/api/authors", method = RequestMethod.POST)
public AuthorDTO addNewAuthor(@RequestBody AuthorDTO authorDTO) {
return authorService.add(authorDTO);
}
(authorService.add
returns an AuthorDTO
type.)
AuthorDTD.java:
public class AuthorDTO {
public AuthorDTO() {
}
public AuthorDTO(Author author) {
this.id = author.getId();
this.first_name = author.getFirstName();
this.last_name = author.getLastName();
}
public AuthorDTO(Long id, String first_name, String last_name) {
this.id = id;
this.first_name = first_name;
this.last_name = last_name;
}
private Long id;
private String first_name;
private String last_name;
//getter/setters
}
And here is my rest test window:
But when i send the POST
request, nothing happens!
json sent: {"id":"12"}, {"first_name":"aaaa"}, { "last_name": "gggg"}
Outputs:
response windows: <Response body is empty>
Run log:
2016-01-13 09:40:18.206 INFO 3892 --- [nio-8082-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-01-13 09:40:18.206 INFO 3892 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-01-13 09:40:18.338 INFO 3892 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 132 ms
Upvotes: 1
Views: 810
Reputation: 5268
Check the format of JSON, it should be,
{"id":12, "first_name":"aaaa", "last_name": "gggg"}
Make sure Content-Type
header is set to application/json
Upvotes: 2