liyifeng1994 / ssm

手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis

Home Page:http://blog.csdn.net/qq598535550/article/details/51703190

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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。当时应该是为了演示更多的写法才这样写的,感谢提出质疑。