mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
2023-09-11 14:18:15 时间
mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
==============================
蕃薯耀 2018年3月14日
http://www.cnblogs.com/fanshuyao/
一、使用Maven方式引入Mybatis依赖Jar包(版本号自己改或定义)
- <properties>
- <spring.version>4.3.13.RELEASE</spring.version>
- <mybatis.version>3.4.6</mybatis.version>
- <mybatis.spring.version>1.3.1</mybatis.spring.version>
- <mybatis.generator.version>1.3.6</mybatis.generator.version>
- <junit.version>4.12</junit.version>
- </properties>
- <!-- mybatis-->
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>${mybatis.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- <version>${mybatis.spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-core</artifactId>
- <version>${mybatis.generator.version}</version>
- <scope>provided</scope>
- </dependency>
二、加入文件生成xml配置文件
直接在项目文件夹下建立xml配置文件:mybatis-generator.xml,内容如下:
- <?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">
- <!-- 配置文件信息见:http://www.mybatis.org/generator/configreference/xmlconfig.html -->
- <generatorConfiguration>
- <!-- 配置数据库信息 -->
- <context id="mysql" targetRuntime="MyBatis3">
- <commentGenerator>
- <!-- 设置不生成注释 suppressAllComments :When the property is true, no comments will be added to any generated element.-->
- <property name="suppressAllComments" value="true" />
- </commentGenerator>
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
- userId="root"
- password="root">
- </jdbcConnection>
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <!-- 指定JavaBean生成的位置,.\src表示直接在项目的src目录下生成 -->
- <javaModelGenerator targetPackage="com.lqy.ssm.bean" targetProject=".\src\main\java">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <!-- 指定sql映射文件生成的位置 -->
- <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <!-- 指定dao接口生成的位置 -->
- <javaClientGenerator type="XMLMAPPER" targetPackage="com.lqy.ssm.dao" targetProject=".\src\main\java">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- 指定每个table表生成的策略 -->
- <!-- domainObjectName可省略 -->
- <table tableName="user" domainObjectName="User"
- enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"></table>
- <table tableName="user_ext"
- enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"></table>
- </context>
- </generatorConfiguration>
把数据库连接信息修改为自己的数据库连接。
三、创建生成文件的代码类:MybatisGenerator.java,内容如下:
官网代码见:http://www.mybatis.org/generator/running/runningWithJava.html
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
- import org.mybatis.generator.api.MyBatisGenerator;
- import org.mybatis.generator.config.Configuration;
- import org.mybatis.generator.config.xml.ConfigurationParser;
- import org.mybatis.generator.internal.DefaultShellCallback;
- public class MybatisGenerator {
- public static void main(String[] args) throws Exception {
- List<String> warnings = new ArrayList<String>();
- boolean overwrite = true;
- File configFile = new File("mybatis-generator.xml");
- ConfigurationParser cp = new ConfigurationParser(warnings);
- Configuration config = cp.parseConfiguration(configFile);
- DefaultShellCallback callback = new DefaultShellCallback(overwrite);
- MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
- myBatisGenerator.generate(null);
- }
- }
其中File configFile = new File("mybatis-generator.xml");就是读取自己的配置文件,如果命名不一致,需要改为一致。
四、最后运行MybatisGenerator方法生成文件,然后F5刷新项目,文件就直接生成。
==============================
蕃薯耀 2018年3月14日
http://www.cnblogs.com/fanshuyao/
相关文章
- 配置php.ini实现PHP文件上传功能
- Node.js文件操作二
- ssm(Spring+Spring mvc+mybatis)Dao层配置sql的文件——DeptDaoMapper.xml
- Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
- Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
- Mybatis+mysql动态分页查询数据案例——配置映射文件(HouseDaoMapper.xml)
- Linux中文件描述符fd和文件指针flip的理解
- spring mvc: 静态资源/文件配置
- 分享七:文件处理
- 在Python中操作文件之truncate()方法的使用教程
- gradle上传本地文件到远程maven库(nexus服务器)
- 修改tnsnames.ora文件中配置内容中的连接别名后,连接超时解决办法
- 深入浅出Mybatis系列(二)---配置简介(mybatis源码篇)
- 深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)
- ifcfg-<interface-name> 文件配置详解
- 配置.dockerignore文件以排除路径,避免打包进image镜像文件
- H7-TOOL固件升级至V1.44,全面支持USB和以太网两种脱机烧录文件配置和传输方式,并且都可以使用LUA功能了
- 如何将一个PDF文件里的图片批量导出
- WCF HTTP 错误 404.3 - Not Found(由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。)
- Atitit mybatis spring整合。读取spring、yml、文件的mysql url 步骤,读取yml,文件,使用ongl定位到url pwd usr 读取mybatis模板配置,
- Atitit mybatisutil 模块测试功能列表 1.1. mybatis读取mapper配置的sql语句 使用xml类库1 1.2. Mybatis替换参数工具类型3 Itfs pn
- Atitit spring单元测试 注解 获取服务名 Spring文件单独放在一个文件夹,去掉dubbo配置,方便测试 里面包含的mybatis 找不到,只好设置成相对于class绝对路径可以了
- atitit.手动配置列表文件的选择and 数据的层次结构 attilax总结最佳实践--yaml
- user.config.ts文件里定义的配置是如何合并到SAP Spartacus的标准配置里去的
- web.xml引用外部xml文件。以及org.xml.sax.SAXException
- CV之NS之VGG16:基于预训练模型VGG16训练COCO的train2014数据集实现训练《神奈川冲浪里》风格配置yml文件
- Python Flask框架学习28:初始化项目文件/配置路由
- linux的PAM认证和shadow文件中密码的加密方式
- [DB][mybatis]MyBatis mapper文件引用变量#{}与${}差异
- rm命令反向选择删除文件
- 《Web安全渗透全套教程(40集)》学习笔记 | 文件上传漏洞原理及实验
- Windows一招解决文件被占用无法删除问题
- hibernate.cfg.xml文件的配置模板和不同数据库的配置參数
- C#读取excel文件到datatable
- hbase-default.xml 默认文件
- PostgreSQL的学习心得和知识总结(二十四)|CentOS环境 配置生成coredump程序崩溃内存转储文件及gdb调试core文件
- 2022年山东省职业院校技能大赛服务器配置及应用项目评分文件