目录
分析如图:

步骤:
1,mapper层,service层
usermapper.xml
-
-
- <select id="selectRoleIdByUserName" resultType="java.lang.String" parameterType="java.lang.String" >
- select
- <include refid="Base_Column_List" />
- select roleid from t_shiro_user u,t_shiro_user_role ur
- where u.userid=ur.userid and u.username = #{userName}
- </select>
- <!---->
-
- <select id="selectPerIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String" >
- select
- <include refid="Base_Column_List" />
- select rp.perid from t_shiro_user u,t_shiro_user_role ur ,t_shiro_role_permission rp
- where u.userid= ur.userid and ur.roleid=rp.roleid and u.username = #{userName}
- </select>
-
-
usermapper.java类
- //角色编号查找
- Set<String> selectRoleIdByUserName(@Param("userName") String username);
- //查看权限
- Set<String> selectPerIdsByUserName(@Param("userName") String username);
实现类
- package com.zking.oa.biz;
-
- import com.zking.oa.mapper.UserMapper;
- import com.zking.oa.model.User;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
-
- import java.util.Set;
-
- /**
- * @author 锦鲤
- * @site www.lucy.com
- * @company xxx公司
- * @create 2022-08-25 18:47
- * //@ContextConfiguration(locations = "classpath:applicationContext-shiro.xml","classpath:UserMapper.xml")
- */
-
- @Service("userbiz")
- public class UserBizImpl implements UserBiz {
-
- @Autowired
- private UserMapper usermapper;
-
- @Override
- public int deleteByPrimaryKey(Integer userid) {
- return usermapper.deleteByPrimaryKey(userid);
- }
-
- @Override
- public int insert(User record) {
- return usermapper.insert(record);
-
- }
-
- @Override
- public int insertSelective(User record) {
- return usermapper.insertSelective(record);
-
- }
-
- @Override
- public User selectByPrimaryKey(Integer userid) {
-
- return usermapper.selectByPrimaryKey(userid);
- }
-
- @Override
- public int updateByPrimaryKeySelective(User record) {
-
- return usermapper.updateByPrimaryKeySelective(record);
-
- }
-
- @Override
- public int updateByPrimaryKey(User record) {
- return usermapper.updateByPrimaryKey(record);
- }
-
- @Override
- public User queryUserByUserName(String userName) {
-
- return usermapper.queryUserByUserName(userName);
-
- }
-
- @Override
- public Set<String> selectRoleIdByUserName(String username) {
- return usermapper.selectRoleIdByUserName(username);
- }
-
- @Override
- public Set<String> selectPerIdsByUserName(String username) {
- return usermapper.selectPerIdsByUserName(username);
- }
- }
2,shiro的授权方法
- package com.zking.oa.controller;
-
- import org.apache.shiro.SecurityUtils;
- import org.apache.shiro.authc.UsernamePasswordToken;
- import org.apache.shiro.subject.Subject;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- import javax.servlet.http.HttpServletRequest;
-
- /**
- * @author 锦鲤
- * @site www.lucy.com
- * @company xxx公司
- * @create 2022-08-19 21:46