只能点赞别人的评论,自己的没有反应
来源:5-10 会员点赞的核心实现
不才少年
2020-12-11 17:04:54
# 具体遇到的问题
当点击别人的评论时点赞数会增加,但是点赞自己的没有任何反应
# 报错信息的截图
17:02:52 DEBUG [http-nio-8080-exec-5] o.s.w.s.DispatcherServlet - POST "/enjoy", parameters={masked}
17:02:52 DEBUG [http-nio-8080-exec-5] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to com.imooc.reader.controller.MemberController#evaluate(Long)
17:02:52 DEBUG [http-nio-8080-exec-5] o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Could not resolve parameter [0] in public java.util.Map com.imooc.reader.controller.MemberController.evaluate(java.lang.Long): Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "2,136"
17:02:52 WARN [http-nio-8080-exec-5] o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "2,136"]
17:02:52 DEBUG [http-nio-8080-exec-5] o.s.w.s.DispatcherServlet - Completed 400 BAD_REQUEST
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
impl:
public Evaluation enjoy(Long evaluationId) {
Evaluation evaluation=evaluationMapper.selectById(evaluationId);
evaluation.setEnjoy(evaluation.getEnjoy()+1);
evaluationMapper.updateById(evaluation);
return evaluation;
}controller:
@PostMapping("/enjoy")
@ResponseBody
public Map evaluate(Long evaluationId){
Map result=new HashMap();
try {
Evaluation eva=memberService.enjoy(evaluationId);
result.put("code","0");
result.put("msg","success");
result.put("evaluation",eva);
}catch (BussinessException ex){
ex.printStackTrace();
result.put("code",ex.getCode());
result.put("msg",ex.getMsg());
}
return result;
}ftl页面:
//评论点赞
$("*[data-evaluation-id]").click(function (){
var evaluationId=$(this).data("evaluation-id");
$.post("/enjoy",{evaluationId:evaluationId},function (json){
if(json.code=="0"){
$("*[data-evaluation-id='"+evaluationId+"'] span").text(json.evaluation.enjoy);
}
},"json")
})
1回答
好帮手慕小脸
2020-12-11
同学你好,
1、经测试运行同学贴出的代码是可以点赞自己的,如下所示:

建议同学查看自己浏览器的控制台是否出现报错,如果有,将错误信息贴出,便于老师定位问题
2、同学也可以尝试下载课程源码试试~
祝学习愉快~
相似问题