controller有问题
liug222 opened this issue · comments
正在转后台开发,拿着你的项目来入门,发现有一个问题,就是在controller里有个bug,最后一个函数,我做了修改。
@RequestMapping(value = "/{bookId}/{studentId}", method = RequestMethod.POST, produces = {
"application/json; charset=utf-8" })
@responsebody
private Result appoint(@PathVariable("bookId") Long bookId, @PathVariable("studentId") Long studentId) {
if (studentId == null || studentId.equals("")) {
return new Result(false, "学号不能为空");
}
AppointExecution execution = bookService.appoint(bookId, studentId);
return new Result(true, execution);
}
你是改了注解的value值吗
因为要返回json数据,所以要加@responsebody注解
是,案例中最后一个方法@RequestMapping的produces指定返回的内容类型,也相当于@responsebody,所以返回类型还是json。当时应该是为了演示更多的写法才这样写的,感谢提出质疑。