1 在MySQL数据库中创建相应的表

/*
Navicat MySQL Data Transfer Source Server : 虚拟机_zeus01
Source Server Version : 50717
Source Host : 10.24.3.108:3306
Source Database : security Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001 Date: 2017-12-10 16:44:58
*/ SET FOREIGN_KEY_CHECKS=0; -- ----------------------------
-- Table structure for `sys_acl`
-- ----------------------------
DROP TABLE IF EXISTS `sys_acl`;
CREATE TABLE `sys_acl` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限ID',
`code` varchar(20) NOT NULL DEFAULT '' COMMENT '权限码',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '权限名称',
`acl_module_id` int(11) NOT NULL DEFAULT '0' COMMENT '权限所在的权限模块ID',
`url` varchar(100) NOT NULL DEFAULT '' COMMENT '请求的URL,可以填正则表达式',
`type` int(11) NOT NULL DEFAULT '3' COMMENT '类型,1:菜单,2:按钮,3:其他',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:正常,0:冻结',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '权限在当前模块的顺序,有效到大',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者的IP地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_acl
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_acl_module`
-- ----------------------------
DROP TABLE IF EXISTS `sys_acl_module`;
CREATE TABLE `sys_acl_module` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限模块ID',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '权限模块名称',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级权限模块ID',
`level` varchar(200) NOT NULL DEFAULT '' COMMENT '权限模块层级',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '权限模块在当前层级的顺序,由小到大',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:正常,0:冻结',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新的操作者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次修改时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的IP地址 ',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_acl_module
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_dept`
-- ----------------------------
DROP TABLE IF EXISTS `sys_dept`;
CREATE TABLE `sys_dept` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '部门ID',
`name` varchar(20) NOT NULL DEFAULT '' COMMENT '部门名称',
`parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级部门ID',
`level` varchar(200) NOT NULL DEFAULT '' COMMENT '部门层级',
`seq` int(11) NOT NULL DEFAULT '0' COMMENT '部门在当前层级的顺序,由小到大',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新的操作者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次修改时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的IP地址 ',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_dept
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_log`
-- ----------------------------
DROP TABLE IF EXISTS `sys_log`;
CREATE TABLE `sys_log` (
` id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(11) NOT NULL DEFAULT '0' COMMENT '权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系',
`target_id` int(11) NOT NULL COMMENT '基于type后制定的对象ID,比如用户、权限、角色等表的主键',
`old_value` text COMMENT '原始值',
`new_value` text COMMENT '新值',
`status` int(11) NOT NULL DEFAULT '0' COMMENT '当前是否复原过,0:没有,1:复原过',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者的IP地址',
PRIMARY KEY (` id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_log
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_role`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色ID',
`name` varchar(20) NOT NULL DEFAULT '',
`type` int(11) NOT NULL DEFAULT '1' COMMENT '角色类型,1:管理角色,2:其他',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,1:可用,0:冻结',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者的IP地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_role
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_role_acl`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_acl`;
CREATE TABLE `sys_role_acl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`role_id` int(11) NOT NULL COMMENT '角色ID',
`acl_id` int(11) NOT NULL COMMENT '权限ID',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者的IP地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_role_acl
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_role_user`
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_user`;
CREATE TABLE `sys_role_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`role_id` int(11) NOT NULL COMMENT '角色ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者的IP地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_role_user
-- ---------------------------- -- ----------------------------
-- Table structure for `sys_user`
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
`username` varchar(20) NOT NULL DEFAULT '' COMMENT '用户名称',
`telephone` varchar(13) NOT NULL DEFAULT '' COMMENT '手机号',
`email` varchar(20) NOT NULL DEFAULT '' COMMENT '邮箱',
`password` varchar(40) NOT NULL DEFAULT '' COMMENT '加密后的密码',
`dept_id` int(11) NOT NULL DEFAULT '0' COMMENT '所在部门的ID',
`status` int(11) NOT NULL DEFAULT '1' COMMENT '状态, 1:正常,0:冻结,2:删除',
`remark` varchar(200) DEFAULT '' COMMENT '备注',
`operator` varchar(20) NOT NULL DEFAULT '' COMMENT '最后更新者',
`operator_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后更新时间',
`operator_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新者的IP',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ----------------------------
-- Records of sys_user
-- ----------------------------

create.sql

2 导入generator工具文件夹到springMVC项目根目录下

生成工具包:点击获取

3 根据自己的项目修改生成配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 数据库驱动包位置 -->
<classPathEntry location="F:\javaProgramming\springCloud\permission\generator\mysql-connector-java-5.1.34.jar" /> <!-- 1 -->
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://10.24.3.108:3306/security?characterEncoding=utf8" userId="root" password="123456"> <!-- 2 -->
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置 --> <!-- 3 -->
<javaModelGenerator targetPackage="cn.xiangxu.model" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 --> <!-- 4 -->
<sqlMapGenerator targetPackage="cn.xiangxu.mapper" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 --> <!-- 5 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.xiangxu.dao" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成那些表(更改tableName和domainObjectName就可以) --><!-- 6 -->
<table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_dept" domainObjectName="SysDept" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl" domainObjectName="SysAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl_module" domainObjectName="SysAclModule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role" domainObjectName="SysRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_acl" domainObjectName="SysRoleAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_user" domainObjectName="SysRoleUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_log" domainObjectName="SysLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
</context>
</generatorConfiguration>

生成文件

  3.1 修改驱动包的位置

    

<classPathEntry location="F:\javaProgramming\springCloud\permission\generator\mysql-connector-java-5.1.34.jar" /> <!-- 1 -->

  3.2 修改数据库连接信息

    

<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://IP地址:端口/数据库?characterEncoding=utf8" userId="用户名" password="密码">  <!-- 2 -->

  3.3 修改生成文件的包名和存放路径

    

<!-- 生成模型的包名和位置 --> <!-- 3 -->
<javaModelGenerator targetPackage="cn.xiangxu.model" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 --> <!-- 4 -->
<sqlMapGenerator targetPackage="cn.xiangxu.mapper" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 --> <!-- 5 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.xiangxu.dao" targetProject="F:\javaProgramming\springCloud\permission\generator\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>

  3.4 设置数据库表名和model、dao、mapper的对应关系

    

<!-- 要生成那些表(更改tableName和domainObjectName就可以) --><!-- 6 -->
<table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_dept" domainObjectName="SysDept" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl" domainObjectName="SysAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_acl_module" domainObjectName="SysAclModule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role" domainObjectName="SysRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_acl" domainObjectName="SysRoleAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_role_user" domainObjectName="SysRoleUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
<table tableName="sys_log" domainObjectName="SysLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />

  3.5 执行生成语句

    java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

 

4 生成效果

  

  执行成功后控制台输出

    

  4.1 执行前的目录结构

    

  4.2 执行后的目录结构

    

利用generator自动生成model(实体)、dao(接口)、mapper(映射)的更多相关文章

  1. mybatis自动生成model、dao及对应的mapper.xml文件

    背景: 日常开发中,如果新建表,手动敲写model.dao和对应的mapper.xml文件,费时费力且容易出错, 所以采用mybatis自动生成model.dao及对应的mapper.xml文件.代码 ...

  2. 基于OCILIB的oracle数据库操作总结及自动生成Model和Dao的工具

    基于OCILIB的oracle数据库操作总结 1.       类图 2.       基类BaseOCIDao的设计与实现 BaseOCIDao.h头文件 #pragma once /* ----- ...

  3. MyBatis 使用Generator自动生成Model , Dao, mapper

    最近   我新建了一 个maven 项目,使用的是spring + springmvc + mybatis框架. 听说Mybatis可以自动生成model和mapper以及dao层,我就从网上查了查资 ...

  4. mybatis自动生成service、dao、mapper

    1.config.properties ## 数据库连接参数 jdbc.driverClass = com.mysql.jdbc.Driver jdbc.url = jdbc:mysql://loca ...

  5. 使用MybatisGenerator自动生成Model,Mapping和Mapper文件

    Mybatis和Hibernate都是持久层框架,MyBatis出现的比Hibernate晚,这两种框架我都用过,对于二者的优势我的感触不深,个人感觉MyBatis自动生成model,Mapping, ...

  6. 一个简单的Java代码生成工具—根据数据源自动生成bean、dao、mapper.xml、service、serviceImpl

    目录结构 核心思想 通过properties文件获取数据源—>获取数据表的字段名称.字段类型等—>生成相应的bean实体类(po.model).dao接口(基本的增删改查).mapper. ...

  7. 使用mybatis-generator自动生成model、dao、mapping文件

    参考文献:http://www.cnblogs.com/smileberry/p/4145872.html 一.所需库 1.mybatis-generator库 2.连接DB的驱动(此以mysql为例 ...

  8. idea使用generator自动生成model、mapper、mapper.xml(转)

    原文链接:http://www.mamicode.com/info-detail-445217.html TEP 0.在Intellij IDEA创建maven项目(本过程比较简单,略) STEP 1 ...

  9. 使用Generator 自动生成 model mapper mapping 文件

    1.下载包 地址http://download.csdn.net/detail/u012909091/7206091 2.下载完成解压文件到任意目录 3.删除下mybatis-generator-co ...

随机推荐

  1. C/S架构自动化测试入门

    所谓C/S架构即Client/Server(客户端/服务器架构).虽然近年来C/S架构产品越来越少,大有被B/S(Browser/Server 浏览器/服务器)架构超越的趋势,但C/S还是有B/S不可 ...

  2. MySQL的安装(比较详细的安装步骤,包括客户端和服务端的安装,还有环境变量的配置以及使用Windows service启动MySQL)

    1.MySQL官网下载操作系统对应的MySQL安装包,解压之后就可以直接使用(免安装). MySQL安装包,一种是MySQL Enterprise Edition (commercial)企业版,还有 ...

  3. URL, URI, URN三者区别

    URL和URN都是URI的子集 URL和URN都是URI,但是URI不一定是URL或者URN URI,URL,URN关系图 关于URL: URL是URI的一种,不仅标识了Web 资源,还指定了操作或者 ...

  4. Laravel 5 框架性能优化技巧

    性能一直是 Laravel 框架为人诟病的一个点,所以调优 Laravel 程序算是一个必学的技能. 接下来分享一些开发的最佳实践,还有调优技巧,大家有别的建议也欢迎留言讨论 1.配置缓存信息 使用l ...

  5. Linux yum安装和源码安装

    转载注明出处:原文地址 Linux Yum 在线安装 在线:Yum配置地址:/etc/yum.repos.d/CentOS-Base.repo 离线:光盘搭建Yum源 挂载光盘 使在线Yum源失效:m ...

  6. centOS 搭建pipelineDB docs

    #下载docs git clone https://github.com/pipelinedb/docs.git #安装python-sphinx &python-dev yum instal ...

  7. git以及github的初级入门(一)

    本身学习git的操作是没什么兴趣的,毕竟原本是win平台学的java开发,git下那么多复制的命令行操作确实比较让人头疼,直到昨天我打开计算机的时候,我放置项目的E盘,以及F盘,G盘盘符都不见了!!我 ...

  8. drupal 开发简单站点流程

    友情推广:Uminicmf 一个基于thinkphp开发的OA框架.http://blog.csdn.net/youmypig/article/details/51727713 drupal 简单站点 ...

  9. hdu 5225 Tom and permutation(回溯)

    题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...

  10. python文件和文件夹訪问File and Directory Access

    http://blog.csdn.net/pipisorry/article/details/47907589 os.path - Common pathname manipulations 都是和路 ...