springboot + vue 前后端分离代码生成器,毕设好帮手

article/2025/9/29 3:18:19

hello 大家好,最近搞了一个前后端代码生成器。只需设计好数据库,就可以自动生成前端页面包括图片上传和后端代码。下面给大家介绍一下。

项目环境:jdk8、node12、maven、mysql、vue2

技术介绍:SpringSecurity、SpringBoot、swagger、elementUi、vue.js

功能介绍:权限管理,动态生成菜单,图标库,swagger文档,可视化,系统sql执行监控

效果演示


密码:123456

权限和菜单管理代码:

package com.admin.security.config;import com.admin.security.evaluator.UserPermissionEvaluator;
import com.admin.security.filter.JWTAuthenticationTokenFilter;
import com.admin.security.handler.*;
import com.admin.security.provider.UserAuthenticationProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;/*** @Author 染柒* @Date 2020/12/6 14:51* @Version 1.0*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) //开启权限注解,默认是关闭的
public class SecurityConfig extends WebSecurityConfigurerAdapter {/*** 自定义登录成功处理器*/@Autowiredprivate UserLoginSuccessHandler userLoginSuccessHandler;/*** 自定义登录失败处理器*/@Autowiredprivate UserLoginFailureHandler userLoginFailureHandler;/*** 自定义注销成功处理器*/@Autowiredprivate UserLogoutSuccessHandler userLogoutSuccessHandler;/*** 自定义暂无权限处理器*/@Autowiredprivate UserAuthAccessDeniedHandler userAuthAccessDeniedHandler;/*** 自定义未登录的处理器*/@Autowiredprivate UserAuthenticationEntryPointHandler userAuthenticationEntryPointHandler;/*** 自定义登录逻辑验证器*/@Autowiredprivate UserAuthenticationProvider userAuthenticationProvider;/*** 加密方式* @Author 染柒* @CreateTime 2019/10/1 14:00*/@Beanpublic BCryptPasswordEncoder bCryptPasswordEncoder(){return new BCryptPasswordEncoder();}/*** 注入自定义PermissionEvaluator*/@Beanpublic DefaultWebSecurityExpressionHandler userSecurityExpressionHandler(){DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();handler.setPermissionEvaluator(new UserPermissionEvaluator());return handler;}/*** 配置登录验证逻辑*/@Overrideprotected void configure(AuthenticationManagerBuilder auth){//这里可启用我们自己的登陆验证逻辑auth.authenticationProvider(userAuthenticationProvider);}/*** 配置security的控制逻辑* @Author 染柒* @CreateTime 2019/10/1 16:56* @Param  http 请求*/@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests()// 不进行权限验证的请求或资源(从配置文件中读取).antMatchers(JWTConfig.antMatchers.split(",")).permitAll()// 其他的需要登陆后才能访问.anyRequest().authenticated().and().headers().frameOptions().disable().and()// 配置未登录自定义处理类.httpBasic().authenticationEntryPoint(userAuthenticationEntryPointHandler).and()// 配置登录地址.formLogin().loginProcessingUrl("/login/userLogin")// 配置登录成功自定义处理类.successHandler(userLoginSuccessHandler)// 配置登录失败自定义处理类.failureHandler(userLoginFailureHandler).and()// 配置登出地址.logout().logoutUrl("/login/userLogout")// 配置用户登出自定义处理类.logoutSuccessHandler(userLogoutSuccessHandler).and()// 配置没有权限自定义处理类.exceptionHandling().accessDeniedHandler(userAuthAccessDeniedHandler).and()// 开启跨域.cors().and()// 取消跨站请求伪造防护.csrf().disable();// 基于Token不需要sessionhttp.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);// 禁用缓存http.headers().cacheControl();// 添加JWT过滤器http.addFilter(new JWTAuthenticationTokenFilter(authenticationManager()));}}
package com.admin.system.controller;import com.admin.common.response.Result;
import com.admin.common.utils.Page;
import com.admin.system.mapper.MenuMapper;
import com.admin.system.pojo.Menu;
import com.admin.system.service.MenuService;
import com.admin.system.vo.MenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import static com.admin.system.utils.Convert.convertToMenuVo;
import static com.admin.system.utils.FindChild.findMenuChild;
import static com.admin.system.utils.FindRoot.findMenuRoot;/*** <p>*  前端控制器* </p>** @author 染柒* @since 2022-04-04*/
@RestController
@RequestMapping("/menu")
@Api(value = "系统菜单模块",tags = "系统菜单接口")
public class MenuController {@Resourceprivate MenuService menuService;@Resourceprivate MenuMapper menuMapper;@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/menuList",method = RequestMethod.POST)@ApiOperation(value = "分页查询菜单信息",notes = "分页查询菜单信息")public Result getByPage(@RequestBody Page<Menu> page){page = menuService.getAllByPage(page);return  Result.ok().data("data",page);}@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/getAllMenu",method = RequestMethod.GET)@ApiOperation(value = "查询所有菜单信息",notes = "查询所有菜单信息")public Result getAllMenu(){List<Menu> menuList = menuMapper.selectAll();/*将menuList转换成menuVoList*/List<MenuVo> menuVoList = convertToMenuVo(menuList);/*找根节点*/List<MenuVo> rootMenu = findMenuRoot(menuVoList);/*为根节点设置子菜单*/for(MenuVo menuVo : rootMenu){/*获取某个根节点的子菜单*/List<MenuVo> childList = findMenuChild(menuVo.getId(),menuVoList);menuVo.setChildren(childList);}List<Integer> ids = menuService.findOpenIds();Map<String, Object> map = new HashMap<>();map.put("tree", rootMenu);map.put("open", ids);return  Result.ok().data("data",map);}@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/addMenu",method = RequestMethod.POST)@ApiOperation(value = "添加菜单",notes = "添加菜单")public Result addMenu(@RequestBody Menu menu){boolean  check =menuService.save(menu);return  Result.ok().message("添加成功!");}@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/deleteMenu/{id}",method = RequestMethod.DELETE)@ApiOperation(value = "根据ID删除菜单",notes = "根据ID删除菜单")public Result deleteMenu(@PathVariable Integer id){boolean check = menuService.removeById(id);if (check == true){return  Result.ok().message("删除成功!");}else{return Result.error().message("删除失败!");}}@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/viewMenu/{id}",method = RequestMethod.GET)@ApiOperation(value = "根据ID查看用户菜单",notes = "根据ID查看用户菜单")public Result viewMenu(@PathVariable Integer id){Menu menu = menuService.getById(id);return  Result.ok().data("data",menu);}@PreAuthorize("hasRole('SUPERADMIN')")@RequestMapping(value = "/update",method = RequestMethod.PUT)@ApiOperation(value = "根据ID更新用户菜单",notes = "根据ID更新用户菜单")public Result update(@RequestBody Menu menu){boolean check = menuService.updateById(menu);if (check == true){return  Result.ok().message("更新成功!");}else{return Result.error().message("更新失败!");}}}

前端角色列表:

<template><div v-loading="loading"><!-- 面包导航 --><el-breadcrumb separator="/" style="padding-left:10px;padding-bottom:10px;font-size:12px;"><el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item><el-breadcrumb-item>系统管理</el-breadcrumb-item><el-breadcrumb-item>角色管理</el-breadcrumb-item></el-breadcrumb><!-- 卡片主体 --><el-card class="box-card"><div class="block"><!-- 搜索 --><el-form :inline="true" :model="page" class="demo-form-inline" size="mini"><el-form-item label="名称"><el-input v-model="page.params.nickname" placeholder="角色名称" clearable /></el-form-item><el-form-item label="是否激活"><el-radio-group v-model="page.params.status"><el-radio label="1">是</el-radio><el-radio label="0">否</el-radio></el-radio-group></el-form-item><el-form-item><el-button type="primary" @click="getRoleList" size="mini">查询</el-button></el-form-item></el-form><el-divider/><div style="margin:15px 0px 15px 0"><el-button type="primary" @click="handleView" size="mini" icon="el-icon-plus"></el-button></div><el-table :data="page.list" border style="width: 100%"><el-table-columnfixedtype="index":index="indexMethod"></el-table-column><el-table-column  prop="id" label="ID" width="80" v-if="show"/><el-table-column  prop="roleName" label="角色名称" /><el-table-column prop="remark" label="角色描述" /><el-table-column prop="modifiedTime" label="修改时间"><template slot-scope="scope"><i class="el-icon-time"></i><span style="margin-left: 10px">{{ scope.row.modifiedTime }}</span></template></el-table-column><el-table-column prop="status" label="是否激活"><template slot-scope="scope"><el-switch v-model="scope.row.status" :inactive-value="0" :active-value="1"  @change="changRoleStatus(scope.row)"></el-switch></template></el-table-column><el-table-column  label="操作"  fixed="right"><template slot-scope="scope"><el-button @click="handleEdit(scope.row.id)" type="primary" icon="el-icon-edit" size="small" circle></el-button><el-button @click="handleAddMenu(scope.row.id)" type="primary"  size="small" icon="el-icon-menu" circle></el-button><el-button @click="handleDelete(scope.row.id)" type="danger" icon="el-icon-delete" size="small" circle></el-button></template></el-table-column></el-table><!-- 分页 --><el-paginationclass="pagination"@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="page.currentPage":page-sizes="[10, 20, 50, 100]":page-size="page.pageSize"layout="total, sizes, prev, pager, next, jumper":total="page.totalCount"></el-pagination></div></el-card><el-dialog title="分配菜单" :visible.sync="dialogFormVisible" :center="true"><!-- @closeDialog = "closeDialog" 传方法--><addMenu :id="id" @closeDialog = "closeDialog"></addMenu></el-dialog><el-dialog title="添加角色信息" :visible.sync="viewVisible" :center="true"><views  @closeDialog = "closeView" @getRoleList = "getRoleList"></views></el-dialog><el-dialog title="编辑角色信息" :visible.sync="editVisible" :center="true"><update :editForm="editForm" @closeDialog = "closeEdit" @getRoleList = "getRoleList"></update></el-dialog></div>
</template>
<style>
.el-table th,td{ text-align: center !important; }</style>><script>
import roleApi from "@/api/role"
import addMenu from "./doAddMenu"
import { Message } from 'element-ui'
import views from "./view"
import update from "./update"export default {components: {addMenu,update,views},data(){return {page: {currentPage: 1,pageSize:10,totalPage: 0,totalCount:0,params: {},list: []},loading: true,show: false,dialogFormVisible: false,editVisible: false,viewVisible: false,editForm: {},id: ""}},created(){this.getRoleList()setTimeout(() => {this.loading = false;}, 500);},methods:{indexMethod(index) {return (index * 1)+1;},handleSizeChange(val) {this.page.pageSize = valthis.getRoleList()},handleCurrentChange(val) {this.page.currentPage = valthis.getRoleList()},getRoleList(){roleApi.getRoleList(this.page).then(res =>{this.page = res.data.data})},handleEdit(id){roleApi.viewRole(id).then(res => {this.editForm = res.data.data})this.editVisible = true},handleView(){this.viewVisible = true},handleDelete(id){this.$confirm('是否刪除?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'error'}).then(() => {roleApi.deleteRole(id).then(res => {Message.success(res.message)this.getRoleList()})})},handleAddMenu(id){this.id = idthis.dialogFormVisible = true},closeDialog(){this.dialogFormVisible = false},//改变用户禁用状态async changRoleStatus(row) {roleApi.update(row).then(res => {if(row.status == 0){Message.success("已禁用!")}else{Message.success("已激活!")}this.getRoleList()})},closeView(){this.viewVisible = false},closeEdit(){this.editVisible = false},}}
</script>

项目截图
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

欢迎大家来学习交流!


http://chatgpt.dhexx.cn/article/Nw8qZOBM.shtml

相关文章

如何编写自己的代码生成器(理论篇一)

作者简介 一个很懒很懒的程序员 如何编写自己的代码生成器 我平常开发都会用到代码生成器&#xff0c;本文将介绍如何制作属于自己业务的代码生成工具 代码生成器的作用 一个新的需求开发涉及到的数据库表有可能有很多张&#xff0c;每个都需要去写增删改查后台管理页面有很…

简单代码生成工具

代码生成 我们做项目的时候&#xff0c;经常会碰到写一些基础的增删改查代码&#xff0c;所以就写了个代码生成的工具&#xff0c;可根据自己的需求编写相应的代码模板。 大致思路 查询表信息&#xff0c;通过字段类型映射出 java 类型&#xff0c;然后通过模板生成 java 文件…

自制代码生成器(上)

自制代码生成器原因&#xff1a; •Mybatis自带的自动生成代码&#xff0c;不能自定义&#xff0c;各种命名没法改&#xff0c;不能生成controller、service、jsp等页面 如何写代码生成器—模板引擎velocity Velocity-1.7.jar &#xff1a; 模板引擎 commons的2个jar包 &#…

Mybatis 代码生成器

MBG与Example GitHub - mybatis/generator: A code generator for MyBatis. 我们在项目中使用Mybatis的时候&#xff0c;针对需要操作的一张表&#xff0c;需要创建实体类、Mapper映射器、Mapper接口&#xff0c;里面又有很多的字段和方法的配置&#xff0c;这部分的工作是非常…

Java-代码生成器的实现

文章目录 前言一、概述二、手写代码1. 简要说明2. 代码编写3. 完整代码4. 测试效果 三、项目源码 前言 最近看了一个开源的项目&#xff0c;jfinal-layui&#xff0c;然后这个项目里面有一个 代码生成器 的功能 之前虽然有用过代码生成器&#xff0c;但是从来没有看过相关的源…

MyBatis-Plus代码生成器(新)使用

目录 一&#xff0c;MyBatis-Plus基本简介。 二&#xff0c;特性 三&#xff0c;实现代码自动生成工具 3.1&#xff0c;准备一个初始项目&#xff0c;数据表&#xff0c;连接好数据库 3.2&#xff0c;导入Mybatis-Plus相关依赖 3.3&#xff0c;配置数据库配置文件applicat…

快速上手若依代码生成器(2022)

文章目录 前言一、启动若依框架二、使用代码生成器1 导入示例表2 使用自带的代码生成 生成zip文件2.1 Illegal mix of collations报错解决 三 把zip文件的内容粘贴到对应的模块中3.1 粘贴后台代码3.2 粘贴前台代码3.3 运行菜单sql语句 四 重新启动前端后端总结 前言 快速上手使…

若依代码生成器的使用

一、代码生成器的使用 1.新建maven模块 原则上&#xff0c;我们的业务代码和若依系统本身的系统代码是要做隔离的&#xff0c;一方面是易于之后随着若依系统升级而升级&#xff0c;另一方面则是纯粹的合理性考虑。 这里新建一个ruoyi-business模块作为业务代码模块&#xff0c;…

Java代码生成器

项目说明 本项目基于是基于 renren-generator 定制的代码生成器 文章目录 **项目说明**不同点&#xff1a;效果原理分析如何定制开发&#xff1f;更多可能存在的坑代码地址 不同点&#xff1a; 因为本人的公司使用的是 tkmyabtis swagger 构建 rest api,而 renren-generator…

手把手带你实现一个代码生成器

前言 不知各位看官在工作之中有没有陷入过疯狂CV代码、看着密密麻麻的类不想动手&#xff0c;或者把大把的时间花费在底层的情况。以笔者为例&#xff0c;会经常遇到以下两个问题&#xff1a; 隔一段时间就需要构建一个新应用&#xff0c;需要各种复制粘贴&#xff08;缺乏定…

代码生成器 ----一个独立的代码生成器

这里我就没有过多发废话了&#xff0c;直接给正文。下面是代码生成器的一些简单介绍。操作简单没啥难度。 下面是生成器的地址&#xff0c;谢谢您的使用↓ 代码生成器点这儿。 一、基于简单的数据库属性连接 二、浏览器缓存连接历史 1、可以选择历史连接 2、可以清空所有浏…

如何自定义代码生成器(上)

1 概述 1.1 介绍 ​ 在项目开发过程中&#xff0c;有很多业务模块的代码是具有一定规律性的&#xff0c;例如controller控制器、service接口、service实现类、mapper接口、model实体类等等&#xff0c;这部分代码可以使用代码生成器生成&#xff0c;我们就可以将更多的时间放…

Java快速开发之代码生成器

1、代码生成器原理分析 观察我们之前写的代码&#xff0c;会发现其中也会有很多重复内容&#xff0c;比如: 那我们就想&#xff0c;如果我想做一个Book模块的开发&#xff0c;是不是只需要将红色部分的内容全部更换成Book即可&#xff0c;如&#xff1a; 所以我们会发现&#…

代码生成器

目录 引言 1 第一种 1.0 pom依赖 1.1 第一步&#xff1a;配置文件 1.2 第二步&#xff1a;代码生成器 1.3 执行生成 引言 代码生成器&#xff0c;遇到过也使用过很多了&#xff0c;用的时候觉得很简单&#xff0c;但是这个玩意不是开个新项目几乎很少碰到&#xff0c;所…

推荐几个代码自动生成器,神器!!!

20个代码生成框架 老的代码生成器的地址&#xff1a;https://www.cnblogs.com/skyme/archive/2011/12/22/2297592.html 以下是大家推荐的最近很火爆的代码生成器神器。如果有更好的希望大家多多留言&#xff0c;我会及时补充上去。 -------------------------更新补充------…

代码生成器AutoGenerator

简介&#xff1a;AutoGenerator 是 MyBatis-Plus 的代码生成器&#xff0c;通过 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各个模块的代码&#xff0c;极大的提升了开发效率。 简介 | MyBatis-Plus 一、如何使用&#xff1a; 1&#x…

代码生成器-mybatis-plus-generator

我们平时在开发的过程中&#xff0c;对于新建的一张表难免会有对其进行增删改查的操作&#xff0c;而且还要写Controller、service、Mapper、Mapper.xml、PO、VO等等。如果每次都要去写这些跟业务毫不相干但是却又耗时耗力的重复代码这不仅是让开发人员不能专注于业务逻辑甚至可…

HM2022ssm-mp5【MP代码生成器】

1. 代码生成器原理分析 1.1 造句: 我们可以往空白内容进行填词造句&#xff0c;比如: 在比如: 再有&#xff1a; 1.2 观察我们之前写的代码&#xff0c;会发现其中也会有很多重复内容&#xff0c;比如: 那我们就想&#xff0c;如果我想做一个Book模块的开发&#xff0c;是不是只…

MyBatis-Plus——代码生成器的使用

MyBatis-Plus——代码生成器的使用 AutoGenerator 是 MyBatis-Plus 的代码生成器&#xff0c;通过 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各个模块的代码&#xff0c;极大的提升了开发效率。 导入依赖 <dependency><groupI…

推荐几个代码自动生成器,神器

20个代码生成框架 老的代码生成器的地址&#xff1a;https://www.cnblogs.com/skyme/archive/2011/12/22/2297592.html 以下是大家推荐的最近很火爆的代码生成器神器。如果有更好的希望大家多多留言&#xff0c;我会及时补充上去。 2.0 WebFirst .NET Core代码生成器 全新的.…