有时前端传回的数据,在后台部分通过检验,发现数据在数据库不存在。好比登陆的时候,密码错误等等。这时咱们能够经过ModelAndView对象传递这些信息。前端
首先咱们定义一个ModelAndView对象数据库
ModelAndView mav = new ModelAndView("Manual");//Manual是页面名 DBCollection dbCollection1=dsForRW.getDB().getCollection("role"); long count=dbCollection1.find(q2).count();//在role数据库中没有找符合q2的数据 if(count==0){ mav.addObject("errorMessage2","没有该权限"); return mav; }
而后在前端处理咱们选择使用JavaScript弹出一个alertspa
<script> if('${errorMessage1}'!=""){ alert('${errorMessage2}'); } </script>
必定要记住引用${errorMessage2}的时候要用到单引号,不能使用双引号。qaq,被这个坑到了。code