设置用户权限为仅本人数据权限
查看所有用户
查看所有用户只能查看到自己的数据
查看sql语句
发现sql语句自动拼接了部门条件和用户条件
sql语句中的${params.dataScope}实现了语句拼接
@DataScope注解与切面编程
@Override
@DataScope(deptAlias = "d", userAlias = "u")
public List<SysUser> selectUserList(SysUser user)
{
return userMapper.selectUserList(user);
}
在执行上面这段代码之前会执行下面这段代码
@Before("@annotation(controllerDataScope)")
public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable
{
clearDataScope(point);
handleDataScope(point, controllerDataScope);
}
通过用户对应的roles追加条件
else if (DATA_SCOPE_DEPT.equals(dataScope))
{
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ",
deptAlias,user.getDeptId()));
}
最后放入baseEntity中的params属性中
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");