evaluationId传入三位数的可以,超过四位数就不行了。
错误
13:41:12 DEBUG [http-nio-80-exec-8] o.s.w.s.DispatcherServlet - POST "/enjoy", parameters={masked}
13:41:12 DEBUG [http-nio-80-exec-8] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to com.imooc.reader.controller.MemberController#valuation(Long)
13:41:12 DEBUG [http-nio-80-exec-8] o.s.web.method.HandlerMethod - Could not resolve parameter [0] in public java.util.Map com.imooc.reader.controller.MemberController.valuation(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,000"
13:41:12 WARN [http-nio-80-exec-8] 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,000"]
13:41:12 DEBUG [http-nio-80-exec-8] o.s.w.s.DispatcherServlet - Completed 400 BAD_REQUEST
Ajax提交
//评论点赞
$("*[data-evaluation-id]").click(function () {
let 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")
})
MemberController
@PostMapping("/enjoy")
@ResponseBody
public Map valuation(Long evaluationId) {
System.out.println("类型:" + evaluationId.getClass() + "值:" + evaluationId);
Map result = new HashMap();
try {
Evaluation evaluation = memberService.enjoy(evaluationId);
result.put("code", "0");
result.put("msg", "success");
result.put("evaluation", evaluation);
} catch (BussinessException e) {
e.printStackTrace();
result.put("code", e.getCode());
result.put("msg", e.getMsg());
}
return result;
}