首页>代码>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(); } }
最近下载更多
xuweiwowzy LV5
2月24日
wz520135 LV7
2022年11月5日
猜猜21 LV13
2022年6月10日
ssh123 LV10
2022年3月18日
Start1 LV15
2022年3月10日
wanglinddad LV53
2022年3月1日
543666826 LV33
2021年11月20日
zy15587462022 LV8
2021年10月27日
ericxu1116 LV24
2021年7月8日
白帅帅 LV5
2021年4月26日
最近浏览更多
xuweiwowzy LV5
2月24日
做自己的太阳 LV11
2月1日
qq1581551433
1月9日
暂无贡献等级
WBelong LV6
2023年12月26日
oulingqiao LV13
2023年10月17日
ly900121
2023年7月3日
暂无贡献等级
1967862957 LV3
2023年6月5日
黑 LV6
2023年3月29日
uni-code_0123 LV1
2023年3月23日
787194770 LV10
2023年2月22日