@PostMapping("/{id}/updata")
public R<Comment> postComment(
@Validated CommentVo commentVo, BindingResult result,//这是前端传来的参数包装类
@AuthenticationPrincipal UserDetails user,
@PathVariable Integer id){ //这里ID就是"/{id}/updata")
log.debug("收到的评论信息:{}",commentVo);
if(result.hasErrors()){
String msg=result.getFieldError().getDefaultMessage();
return R.unproecsableEntity(msg);
}
//调用业务逻辑层代码
Comment comment=commentService.saveComment(
commentVo,user.getUsername());
return R.created(comment);
}
下面这个是XXXMapper中的注解:(@Param("sql中的变量“) Interger id)
@Repository
public interface AnswerMapper extends BaseMapper<Answer> {
//根据问题id查询所有回答,回答中包含这个回答的所有评论
List<Answer> findAnswersWithCommentByQuestionId(
Integer questionId);
//修改当前回答的采纳状态的方法
@Update("update answer set accept_status=#{acceptStatus}" +
" where id=#{answerId}")
int updateAcceptStatus(@Param("answerId") Integer answerId,
@Param("acceptStatus") Integer acceptStatus);
}