0
本準則做工精細的認可:請求方法不是由Spring REST API
@RestController
@RequestMapping("/api/post")
public class PostController {
@Autowired
private PostService postService;
public PostService getPostService() {
return postService;
}
public void setPostService(PostService postService) {
this.postService = postService;
}
@RequestMapping(value = "/userPost", method = RequestMethod.GET)
@ResponseBody
public String userPost(String username) {
try {
List<Validation> validations = new ArrayList<Validation>();
ValidationHandeler.rejectIfEmptyOrWhitespace(validations, username, "username is requierd");
if (validations.isEmpty()) {
List<Post> followers = getPostService().findUserPost(username);
return new Message(followers, MessageSuccesStatusEnum.SUCCESS).toString();
}
return new Message(validations, MessageSuccesStatusEnum.FAILED).toString();
} catch (Exception ex) {
return new Message("Error retriving follower list : " + ex.toString(), MessageSuccesStatusEnum.FAILED)
.toString();
}
}
,這是輸出:
{"result":"0","info":["username is requierd"]}
,但是當過我改變RequestMethod類型將它張貼給我以下輸出:
{"timestamp":1492948640973,"status":404,"error":"Not Found","message":"No message available","path":"/api/post/userPost"}
確實有任何的身體知道如何解決這個問題?
正如我傷心的文章中,我確實改變了請求類型後,但不工作 –
你是如何測試API,你有CURL請求嗎? –
curl -X POST http:// localhost:8080/api/post/userPost當方法請求類型爲post –