@RequestMapping(value = "/todos/delete", method = RequestMethod.POST)
public String deleteTodo(@RequestBody Todo todo, Model model) {
logger.info("/todos/delete : todo = " + todo);
String status = "ok";
int num = 0;
try {
int id = todo.getId();
num = todoMapper.deleteByPrimaryKey(id);
} catch (Exception e) {
logger.error("/todos/delete failed : " + e);
status = "fail";
}
// result
model.addAttribute("out", "deleted " + num + " todo(s)");
model.addAttribute("status", status);
return jsonTemplate;
}
With curl , I can post it like:
curl -H "Content-Type: application/json" -X POST -d "{\"id\":1}" http://localhost:8080/todo/todos/delete
Then I can get todo initialized.
But if I post with JulianBirch/cljs-ajax :
(ajax/POST "/todo/todos/delete"
{:format :json
:response-format :json
:handler #(dispatch [:handle-del-resp %1])
:error-handler #(dispatch [:handle-error %1])
:params {"id" id}})
I am getting todo return null.
Any point will be appreciated, thanks in advanced!
Point your cURL command at POSTHere.io (you make up whatever URL you want, so I just used the same one you were using, /todo/todos/delete):
curl -H "Content-Type: application/json" -X POST -d "{\"id\":1}" http://posthere.io/todo/todos/delete
And update your CLJS code to use POSTHere.io:
(ajax/POST "http://posthere.io/todo/todos/delete"
{:format :json
:response-format :json
:handler #(dispatch [:handle-del-resp %1])
:error-handler #(dispatch [:handle-error %1])
:params {"id" id}})
Then visit that POSThere.io URL: http://posthere.io/todo/todos/delete
It'll show all the details about your two posts and you can see exactly how they differ.
Cheers,
Sean
http://posthere.io/ is really helped!
It turns out I have to using to transit with :json-verbose , or Spring (w/o transit) will failed to parse things like
[ "^ ", "id", 8 ]
instead of
{
"id" : 2