首页>代码>ssm+shiro+layui+easyui实现的后台权限管理系统>/RMS/src/main/java/SystemManage/Common/controller/BaseController.java
package SystemManage.Common.controller; import SystemManage.UserManage.entity.ShiroUser; import SystemManage.Common.until.StringEscapeEditor; import SystemManage.UserManage.entity.User; import SystemManage.UserManage.service.UserService; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.annotation.InitBinder; import java.text.SimpleDateFormat; import java.util.Date; /** * 基础 Controller */ public class BaseController { @Autowired private UserService userService; @InitBinder public void initBinder(ServletRequestDataBinder binder) { /** * 自动转换日期类型的字段格式 */ binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true)); /** * 防止XSS攻击 */ binder.registerCustomEditor(String.class, new StringEscapeEditor(true, false)); } /** * 获取当前登录用户对象 * @return */ public User getCurrentUser() { ShiroUser shiroUser= (ShiroUser) SecurityUtils.getSubject().getPrincipal(); User currentUser = userService.findUserById(shiroUser.id); return currentUser; } /** * 获取当前登录用户id * @return */ public Long getUserId() { return this.getCurrentUser().getId(); } /** * 获取当前登录用户名 * @return */ public String getStaffName() { return this.getCurrentUser().getName(); } }

泓鼎168 LV20
2024年5月15日
xuweiwowzy LV5
2024年2月24日
wz520135 LV7
2022年11月5日
猜猜21 LV13
2022年6月10日
ssh123 LV10
2022年3月18日
Start1 LV15
2022年3月10日
wanglinddad LV55
2022年3月1日
543666826 LV34
2021年11月20日
zy15587462022 LV8
2021年10月27日
ericxu1116 LV24
2021年7月8日

vincemokea LV5
5月7日
monster_001 LV3
3月25日
qiheideguang LV18
2024年12月4日
zhengguangshun LV4
2024年8月25日
李朝磊 LV18
2024年6月24日
ma406805131 LV19
2024年6月2日
shuiyan LV1
2024年6月1日
泓鼎168 LV20
2024年5月15日
yhe107 LV3
2024年4月17日
xuweiwowzy LV5
2024年2月24日