前言
如果使用JeecgBoot項目進行開發(fā)的時候,有的場景需要獲取當前登錄人信息做一些邏輯操作
下面分享下通過前后端分別獲取用戶的方式
前端獲取
本質(zhì)是使用vuex進行獲取
引入store
import store from '@/store'
使用store獲取
let usercode = store.getters.userInfo.username
后端獲取
org.apache.shiro.SecurityUtils 是使用了Apache Shiro框架的認證,所以這里直接使用SecurityUtils類來獲取用戶即可。
注意: 下面代碼有升級變更,不同的版本對應的獲取方式不一樣
代碼如下:
// 獲取登錄人用戶信息 V1.0版本:
SysUser user= (SysUser)SecurityUtils.getSubject().getPrincipal();
// 獲取登錄人用戶信息 V2.0版本:
LoginUser user= (LoginUser)SecurityUtils.getSubject().getPrincipal();
// 用戶名
String userName=user.getUserName();
// 用戶id
String userId=user.user.getId();
這里我打了個斷點,可以看到相關(guān)信息:文章來源:http://www.zghlxwxcb.cn/news/detail-523593.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-523593.html
到了這里,關(guān)于JeecgBoot獲取當前登錄用戶信息的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!