springBoot2.0 配置shiro实现权限管理( 三 )

roles = new HashSet<>();}
四、dao
.java
package com.example.demo2.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.example.demo2.entity.User;import org.apache.ibatis.annotations.Param;import org.springframework.stereotype.Repository;import java.util.List;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/16*/@Repositorypublic interface UserDao extends BaseMapper {/*** 用户列表* @return*/List getList();User findByUsername(@Param("username") String username);}
.xml
SELECT u.*FROM user uSELECTu.id uid,u.username,u.password,r.id rid,r.name rname,p.id pid,p.name pname,p.urlFROM user uINNER JOIN user_role ur on ur.uid = u.idINNER JOIN role r on r.id = ur.ridINNER JOIN permission_role pr on pr.rid = r.idINNER JOIN permission p on pr.pid = p.idWHERE u.username = #{username}

springBoot2.0 配置shiro实现权限管理

文章插图
package com.example.demo2.service;import com.baomidou.mybatisplus.extension.service.IService;import com.example.demo2.entity.User;import java.util.List;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/16*/public interface UserService extends IService {List getList();User findByUsername(String username);}
package com.example.demo2.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import com.example.demo2.dao.UserDao;import com.example.demo2.entity.User;import com.example.demo2.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.cache.annotation.Cacheable;import org.springframework.stereotype.Service;import java.util.List;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/16*/@Servicepublic class UserServiceImpl extends ServiceImpl implements UserService {@Autowiredprivate UserDao userDao;/** (non-Javadoc)* @value:在redis中 保存缓存在以user命名的集合中* @key:user集合中的关键字,注意字符串要以单引号括住'',变量前缀加#号,如#userId*/@Override@Cacheable(value="http://www.kingceram.com/post/user",key="'list'")public List getList() {return userDao.getList();}@Override@Cacheable(value="http://www.kingceram.com/post/user",key="'userList_'+#username")public User findByUsername(String username) {return userDao.findByUsername(username);}}
六、
package com.example.demo2.controller;import com.example.demo2.entity.User;import com.example.demo2.service.UserService;import org.apache.shiro.SecurityUtils;import org.apache.shiro.authc.UsernamePasswordToken;import org.apache.shiro.authz.annotation.RequiresPermissions;import org.apache.shiro.authz.annotation.RequiresRoles;import org.apache.shiro.subject.Subject;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import java.util.List;/*** @author sssr* @version 1.0* @Description:* @date 2019/2/16*/@RestController@RequestMapping("/user")public class UserController {@Autowiredprivate UserService userService;@GetMapping("/list")public List