写一个网站,网络黄页推广软件,网站栏目怎么做单独的搜索框,建设工业视频链接:08-SpringMVC拦截器-用户登录权限控制代码实现2_哔哩哔哩_bilibili
114
1、做了一个用户跟角色添加的相关操作 1.1 这个后台工程,没有进行相关操作也能够进行登录: 2、现在我做一个用户的权限控制,如果当前我没有进行操… 视频链接:08-SpringMVC拦截器-用户登录权限控制代码实现2_哔哩哔哩_bilibili
114
1、做了一个用户跟角色添加的相关操作
1.1 这个后台工程,没有进行相关操作也能够进行登录:

2、现在我做一个用户的权限控制,如果当前我没有进行操作,那我的后台就不进行操作:同时让你跳转到登录页面

3、功能写到那,写到inter...,控制器里面,专门验证一下,页面有没有进行登录
4、业务流程操作是这样的,如下。用户登还是没登,如何进行判断,用session,进行判断,如果不做集群,存session,如果做集群,存到redis里面
4.1
5、以下为设置拦截器的功能:

5.1
6、现在我们演示的是Spring_interceptor工程中转换到Spring_test工程:

7、我先把他发布过去:

8、移除掉

选择test那个文件:

9、把服务器关掉,然后再重新启动

10、这时候,我要创建一个inter...包

11、建个包

12、创建好之后,我要创建一个权限控制器:

13、

14、写好之后实现固定的那个接口:

15、覆盖一下方法:

16、本质逻辑是判断用户有没有进行登录:

17、session通过request进行获取

17.1.var可以获得session对象:

17.2 获取谁啊!获取user,返回的是user对象
17.3 强转之后做判断:

17.4 如果判断没有登录,这里跳转,这里我要设置重定向命令:

17.5 重定向
17.6 内部requestContextPath,这个可以获取外部名称

17.7 设置request,login.jsp

17.8 你想要这东西,你还得return false 最终不放行

17.9 如果不是null,就可以实现放行

17.10 写完这些之后,可以进行相应的配置

17.11 找到springMVC,将包进行相应的配置

18、内部inter

19、把之前放的路径放到这里;

19.1 配完之后,我们把他发布一下看一下效果

20、效果:这个拦截器,跳转到登录页面已经完成了


21、-------------------接下来实现登录操作
21.1 登录功能比较简单了,表单输入密码和用户名,实现登录:。如果不正确,跳回到我们的登录页面:
22、先找到表单,这里有表单传送数据表单

22.1 设置好路径的方法:接受表单发送过来的数据,这里数据比较少:

22.2 login执行login方法,并把他返回为一个user对象

22.3 之后我再对其进行判断,对其进行session的注入,看到产生形参,我就把session给你
22.4 session的对象就是user

22.5 传递完值之后,跳转页面

22.6 如果登录失败去那跳:继续跳到我们的jsp页面

22. 7 alt + insert 将方法快速实现一下:

其他

22.8 把user给返回一下:同时把username和password的数据传输一下

22.9上面红色标记实现一下方法,alt + insert ,然后实现一下Dao层,点旁边的绿色按钮
22.10 找Dao层进行实现:

22.11 Dao层用jdbc模板,然后你再接收一下实体
22.12 接收一个实体:

22.13 后面是一个User.class字节码类型

22.14 再后面是我们的实参username和password

22.15 这个方法,给我们的返回值返回一下:
22.16 这里面的user,我们就return一下

22.17 发布一下我们就给他return一下:

23、出现了bug,根本就过不去

24、原因是将密码输入完之后,他直接去找我们的资源

24.1 你在找资源,我在配置的时候,配置/**,对任何请求都要执行过滤操作:包括你的login
25 重点我们如何选择对那些资源进行放行:要一个exlude

26、如果你要多个资源,你可以选择多个资源进行配置:

27、放行之后,登录成功

28、密码登录
29、Empty 通的结果的数据返回的异常

30、Dao层数据爆了错

==
31、这就是Dao层:

31.1
32、如果用户密码是错的,查不到user,queryForObject查询不到就会抛出异常,我最终想要转换为null,而不是想要真的异常

33、他为什么返回了真么一个异常:

34、他有这个异常为什么不抓呀! 一般情况下,我们会在业务层进行操作,统一try catch,抛出去谁调用这个try catch方法

34.1、

34.2 catch() 获取对象:
35、try之后,return

36、把异常抛出去,这样就是空的:抛到业务层转成null

37、转成null,转成成功

文章转载自: http://dinncolomilomi.ssfq.cn http://dinncosnowshed.ssfq.cn http://dinncoanomie.ssfq.cn http://dinncoetyma.ssfq.cn http://dinncobre.ssfq.cn http://dinncoscrimshank.ssfq.cn http://dinncomonamide.ssfq.cn http://dinncocineole.ssfq.cn http://dinncovertu.ssfq.cn http://dinncophytoplankter.ssfq.cn http://dinncosundae.ssfq.cn http://dinncolooky.ssfq.cn http://dinncoely.ssfq.cn http://dinncofoulness.ssfq.cn http://dinncoposho.ssfq.cn http://dinncopotstone.ssfq.cn http://dinncodisenablement.ssfq.cn http://dinncoixtle.ssfq.cn http://dinncoapiculturist.ssfq.cn http://dinncogalactorrhea.ssfq.cn http://dinncoirretrievable.ssfq.cn http://dinncoastronome.ssfq.cn http://dinncoquadrivial.ssfq.cn http://dinncoflatette.ssfq.cn http://dinncopaludicolous.ssfq.cn http://dinncoacheulian.ssfq.cn http://dinncobullock.ssfq.cn http://dinncolivingly.ssfq.cn http://dinncoforedate.ssfq.cn http://dinncoclonal.ssfq.cn http://dinncoscotopia.ssfq.cn http://dinncogallica.ssfq.cn http://dinncotendon.ssfq.cn http://dinncospiceberry.ssfq.cn http://dinncointeract.ssfq.cn http://dinncotheopathetic.ssfq.cn http://dinncopolyphyodont.ssfq.cn http://dinncobrunhilde.ssfq.cn http://dinncoapl.ssfq.cn http://dinncowatcher.ssfq.cn http://dinncopursang.ssfq.cn http://dinncorheotropism.ssfq.cn http://dinncofortunehunting.ssfq.cn http://dinncocsf.ssfq.cn http://dinncofermion.ssfq.cn http://dinncopinhole.ssfq.cn http://dinncogaillardia.ssfq.cn http://dinncolimnaeid.ssfq.cn http://dinncofuzznuts.ssfq.cn http://dinncopaca.ssfq.cn http://dinncodemultiplexer.ssfq.cn http://dinncoced.ssfq.cn http://dinncoisolable.ssfq.cn http://dinncodaffadilly.ssfq.cn http://dinncowheat.ssfq.cn http://dinncoghana.ssfq.cn http://dinncochummery.ssfq.cn http://dinncoencephalogram.ssfq.cn http://dinncochurchwoman.ssfq.cn http://dinncohover.ssfq.cn http://dinncodiscursive.ssfq.cn http://dinncoherring.ssfq.cn http://dinncokarlsbad.ssfq.cn http://dinncobegot.ssfq.cn http://dinncosuffuse.ssfq.cn http://dinncoshadepull.ssfq.cn http://dinncognocchi.ssfq.cn http://dinncoworth.ssfq.cn http://dinnconorroy.ssfq.cn http://dinncosurvivalist.ssfq.cn http://dinncomoribund.ssfq.cn http://dinncocompliableness.ssfq.cn http://dinncoprednisolone.ssfq.cn http://dinncorijsttafel.ssfq.cn http://dinncobaciamano.ssfq.cn http://dinncohayburner.ssfq.cn http://dinncotensive.ssfq.cn http://dinncoacinus.ssfq.cn http://dinncocrania.ssfq.cn http://dinncoacetated.ssfq.cn http://dinncokaryomitosis.ssfq.cn http://dinncothroat.ssfq.cn http://dinncomonachism.ssfq.cn http://dinncovinometer.ssfq.cn http://dinncovideography.ssfq.cn http://dinncoilluviation.ssfq.cn http://dinncocilium.ssfq.cn http://dinncologography.ssfq.cn http://dinncolamplighter.ssfq.cn http://dinncopsychanalysis.ssfq.cn http://dinncodamselfish.ssfq.cn http://dinncodisproof.ssfq.cn http://dinncoclocker.ssfq.cn http://dinncosurrealistic.ssfq.cn http://dinncopubescence.ssfq.cn http://dinncotrainable.ssfq.cn http://dinncodolomite.ssfq.cn http://dinncoequatorial.ssfq.cn http://dinncomolybdenite.ssfq.cn http://dinncohalobacteria.ssfq.cn