赞
踩
1.运行环境:最好是java jdk 1.8,在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.数据库:MySql 5.7版本;
1. 后端:SpringBoot
2. 前端:HTML+CSS+JavaScript+jsp
权限相关代码实现
- @RestController
- @RequestMapping("permission")
- public class PermissionController {
-
- @Autowired
- private IPermissionService permissionService;
-
- /**
- * 加载权限左边的权限树
- * @param permissionVo
- * @return
- */
- @RequestMapping("loadPermissionManagerLeftTreeJson")
- public DataGridView loadPermissionManagerLeftTreeJson(PermissionVo permissionVo){
- QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("type", Constast.TYPE_MENU);
- //查询出所有的权限,存放进list中
- List<Permission> list = permissionService.list(queryWrapper);
- List<TreeNode> treeNodes = new ArrayList<>();
- //将权限放入treeNodes中,组装成json
- for (Permission permission : list) {
- Boolean open = permission.getOpen()==1?true:false;
- treeNodes.add(new TreeNode(permission.getId(),permission.getPid(),permission.getTitle(),open));
- }
- return new DataGridView(treeNodes);
- }
-
- /**
- * 查询所有权限数据
- * @param permissionVo
- * @return
- */
- @RequestMapping("loadAllPermission")
- public DataGridView loadAllPermission(PermissionVo permissionVo){
- IPage<Permission> page = new Page<>(permissionVo.getPage(),permissionVo.getLimit());
- //进行模糊查询
- QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
- //只能查询权限
- queryWrapper.eq("type",Constast.TYPE_PERMISSION);
- queryWrapper.like(StringUtils.isNotBlank(permissionVo.getTitle()),"title",permissionVo.getTitle());
- queryWrapper.like(StringUtils.isNotBlank(permissionVo.getPercode()),"percode",permissionVo.getPercode());
- queryWrapper.eq(permissionVo.getId()!=null,"pid",permissionVo.getId());
- queryWrapper.orderByAsc("ordernum");
- //进行查询
- permissionService.page(page,queryWrapper);
- //返回DataGridView
- return new DataGridView(page.getTotal(),page.getRecords());
- }
-
- /**
- * 添加权限
- * @param permissionVo
- * @return
- */
- @RequestMapping("addPermission")
- public ResultObj addPermission(PermissionVo permissionVo){
- try {
- //设置添加类型为 permission
- permissionVo.setType(Constast.TYPE_PERMISSION);
- permissionService.save(permissionVo);
- return ResultObj.ADD_SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- return ResultObj.ADD_ERROR;
- }
- }
-
- /**
- * 加载排序码
- * @return
- */
- @RequestMapping("loadPermissionMaxOrderNum")
- public Map<String,Object> loadPermissionMaxOrderNum(){
- Map<String,Object> map = new HashMap<String,Object>();
- QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
- queryWrapper.orderByDesc("ordernum");
- IPage<Permission> page = new Page<>(1,1);
- List<Permission> list = permissionService.page(page,queryWrapper).getRecords();
- if (list.size()>0){
- map.put("value",list.get(0).getOrdernum()+1);
- }else {
- map.put("value",1);
- }
- return map;
- }
-
- /**
- * 更新权限
- * @param permissionVo
- * @return
- */
- @RequestMapping("updatePermission")
- public ResultObj updatePermission(PermissionVo permissionVo){
- try {
- permissionService.updateById(permissionVo);
- return ResultObj.UPDATE_SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- return ResultObj.UPDATE_ERROR;
- }
- }
-
- /**
- * 检查当前权限是否有子权限
- * @param permissionVo
- * @return
- */
- @RequestMapping("checkPermissionHasChildrenNode")
- public Map<String,Object> checkPermissionHasChildrenNode(PermissionVo permissionVo){
- Map<String,Object> map = new HashMap<String, Object>();
- QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("pid",permissionVo.getId());
- List<Permission> list = permissionService.list(queryWrapper);
- if (list.size()>0){
- map.put("value",true);
- }else {
- map.put("value",false);
- }
- return map;
- }
-
- /**
- * 删除权限
- * @param permissionVo
- * @return
- */
- @RequestMapping("deletePermission")
- public ResultObj deletePermission(PermissionVo permissionVo){
- try {
- permissionService.removeById(permissionVo.getId());
- return ResultObj.DELETE_SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- return ResultObj.DELETE_ERROR;
- }
- }
-
-
- }
-
登录相关代码
- @RestController
- @RequestMapping("login")
- public class LoginController {
-
- @Autowired
- private ILoginfoService loginfoService;
-
- @Autowired
- private IRoleService roleService;
- public static void main(String[] args) {
- String hashAlgorithmName = "MD5";//加密
- String credentials = "123456";//密码
- int hashIterations = 1024; //加密次数
-
- Object obj = new SimpleHash(hashAlgorithmName, credentials, "04A93C74C8294AA09A8B974FD1F4ECBB", 2);//null 为盐
- System.out.println(obj);
- }
- @RequestMapping("login")
- public ResultObj login(UserVo userVo, String code, HttpSession session){
-
- //获得存储在session中的验证码
- String sessionCode = (String) session.getAttribute("code");
- if (code!=null&&sessionCode.equals(code)){
- Subject subject = SecurityUtils.getSubject();
- AuthenticationToken token = new UsernamePasswordToken(userVo.getLoginname(),userVo.getPwd());
- try {
- //对用户进行认证登陆
- subject.login(token);
- //通过subject获取以认证活动的user
- ActiverUser activerUser = (ActiverUser) subject.getPrincipal();
- //将user存储到session中
- WebUtils.getSession().setAttribute("user",activerUser.getUser());
- //查询当前用户拥有的角色
- /* List<Integer> currentUserRoleIds = roleService.queryUserRoleIdsByUid(activerUser.getUser().getId());
- WebUtils.getSession().setAttribute("roles",activerUser.getRoles());
- System.out.println("roles:"+activerUser.getRoles());*/
- //记录登陆日志
- Loginfo entity = new Loginfo();
- entity.setLoginname(activerUser.getUser().getName()+"-"+activerUser.getUser().getLoginname());
- entity.setLoginip(WebUtils.getRequest().getRemoteAddr());
- entity.setLogintime(new Date());
- loginfoService.save(entity);
-
- return ResultObj.LOGIN_SUCCESS;
- } catch (AuthenticationException e) {
- e.printStackTrace();
- return ResultObj.LOGIN_ERROR_PASS;
- }
- }else {
- return ResultObj.LOGIN_ERROR_CODE;
- }
-
- }
-
- /**
- * 得到登陆验证码
- * @param response
- * @param session
- * @throws IOException
- */
- @RequestMapping("getCode")
- public void getCode(HttpServletResponse response, HttpSession session) throws IOException{
- //定义图形验证码的长和宽
- LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36,4,5);
- session.setAttribute("code",lineCaptcha.getCode());
- try {
- ServletOutputStream outputStream = response.getOutputStream();
- lineCaptcha.write(outputStream);
- outputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。