【FAQ】
项目FAQ
做项目时出现的前后端问题如下。
1. SpringBoot 整合 Shiro
时出现错误
问题描述:进入登录页面时,未输入账号密码却报错,在我输入账号密码后,重启服务器后出现,如图:
解决方案:GetMapping("login")是接受页面请求的,此时返回登录界面;PostMapping("login")是接受登录界面的提交请求的,此时登录。
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.shiro.authc.AuthenticationException: Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - null, rememberMe=false]. Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException).] with root cause
2. 前后端交互
Q1:前端使用 Stringify 将数组转换为 JSON 数据传给后端,请问后端如何接收?
后端通过一个@RequestBody Integer[](类型[]格式) ids 来接收。@RequestBody意味着把它当成 JSON 格式接受,然后转为 Java 对象。
错点:误以为和接受普通 params 一样,用 @RequestParam 接收一个列表,或尝试用HttpServletRequest.getParameter来接收、或 JSONObject.forObject(rentTicketIds)。