idea中mybatis generator自动生成代码配置 数据库是sqlserver
好长时间没有写博客了,最近公司要用java语言,开始学习java,属于初学者,今天主要记录一下mybatis generator自动生成代码,首先在如下图的目录中新建两个文件,如下图

generatorConfig.xml and jdbc.properties都要放在resource根目录下
具体generatorConfig.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">
- <generatorConfiguration>
- <properties resource="jdbc.properties"></properties>
- <classPathEntry location="${dbconfig.sqlServer.driverLocation}" />
- <context targetRuntime="MyBatis3">
- <!--<commentGenerator>
- <!– 去除自动生成的注释 –>
- <property name="suppressAllComments" value="true" />
- </commentGenerator>-->
- <!-- 是否生成注释 去除自动生成的注释-->
- <commentGenerator>
- <property name="suppressDate" value="true"/>
- <property name="suppressAllComments" value="true"/>
- </commentGenerator>
- <!-- 数据库连接配置 -->
- <jdbcConnection driverClass="${dbconfig.sqlServer.driverClasss}"
- connectionURL="${dbconfig.sqlServer.ssmDemo.read.jdbcUrl}"
- userId="${dbconfig.sqlServer.username}"
- password="${dbconfig.sqlServer.password}" />
- <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false"/>
- </javaTypeResolver>
- <!--配置生成的实体包
- targetPackage:生成的实体包位置,默认存放在src目录下
- targetProject:目标工程名
- -->
- <javaModelGenerator targetPackage="com.pojo"
- targetProject="src/main/java" />
- <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
- <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources" />
- <!--生成Dao类存放位置-->
- <javaClientGenerator type="XMLMAPPER" targetPackage="com.dao" targetProject="src/main/java">
- <property name="enableSubPackages" value="true"/>
- </javaClientGenerator>
- <!--生成对应表及类名-->
- <!-- 配置表
- schema:不用填写
- tableName: 表名
- enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
- 去除自动生成的例子
- -->
- <table schema="" tableName="UzaiSupplierStore" domainObjectName="UzaiSupplierStore" enableCountByExample="false" enableSelectByExample="false"
- enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
- </table>
- <table schema="" tableName="UzaiCountry" enableCountByExample="false" enableSelectByExample="false"
- enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
- </table>
- </context>
- </generatorConfiguration>
jdbc.properties内容如下
dbconfig.sqlServer.driverClasss=com.microsoft.sqlserver.jdbc.SQLServerDriver
dbconfig.sqlServer.ssmDemo.read.jdbcUrl=jdbc:sqlserver://127.0.0.1;DatabaseName=Travel
dbconfig.sqlServer.username=uzai_trip
dbconfig.sqlServer.password=Flzx3qC!$
#定义初始连接数
dbconfig.initialSize=0
#定义最大连接数
dbconfig.maxActive=20
#定义最大空闲
dbconfig.maxIdle=20
#定义最小空闲
dbconfig.minIdle=1
#定义最长等待时间
dbconfig.maxWait=60000
dbconfig.sqlServer.driverLocation=C:/Users/zd69155/Documents/mssql-jdbc-6.3.0.jre7-preview.jar
C:/Users/zd69155/Documents/mssql-jdbc-6.3.0.jre7-preview.jar这个地址一定是在本地下载好这个jar包的地址
可以添加下面的dependency下载SQLjdbc jar包
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.0.jre7-preview</version>
<scope>test</scope>
</dependency>
jdbc.properties的参数是对应generatorConfig.xml里面的,如下图

然后就是需要配置pom.xml

以上配置完成以后,点run弹出如下界面
mybatis-generator:generate -e
如果碰到这样的错误 “The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed. ClientConnectionId:972101e7-9ee5-4004-9abc-e0e932b921bd"
可以尝试
mybatis-generator:generate -Djdk.tls.client.protocols=TLSv1.2

以上都配置以后点击运行就可以生成了


目前发的生成的dao文件名字是Mapper,还有就是生成的数据库类没有中文注释,大多数解决方案是mysql数据库。关于sqlserver还在进一步了解中
idea中mybatis generator自动生成代码配置 数据库是sqlserver的更多相关文章
- SpringBoot 添加mybatis generator 自动生成代码插件
自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- IDEA Maven Mybatis generator 自动生成代码
IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...
- IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)
IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...
- 使用Mybatis Generator自动生成代码
MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码.它将内省数据库 ...
- IDEA使用mybatis generator自动生成代码
主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...
- MyBatis Generator自动生成的配置及使用
注意:文件名不能有中文字符,不然不能自动生成 找到MyBatis Generator.rar\MyBatis Generator\eclipse里的features和plugins文件,把这两个文件复 ...
- 在IDEA中使用MyBatis Generator自动生成代码
转载自 https://blog.csdn.net/hua_faded/article/details/78900780 一.配置Maven pom.xml 文件 在pom.xml增加以下插件: ...
- Mybatis generator 自动生成代码(2)
最近准备开始做一个项目,需要开始手动创建sql,于是将Mybatis generator 工具功能强化了下. 首先,这里引入到版本一点的包 <dependency> <groupId ...
随机推荐
- [synergy]两台机器公用键盘鼠标
两台机器公用键盘鼠标 如果是Linux: 下载synergy相关的deb包,然后
- Go Revel - server.go 源码分析
之前介绍了 Go Revel - main函数分析 http://www.cnblogs.com/hangxin1940/p/3263775.html 最后会调用 `revel.Run(*port)` ...
- Android——SQLite数据库(二)升级数据库、增、删、改、查、事务
xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- wps不记录打开打开的文件
“工具”中的“选项”后,进入选项界面,在“常规与保存”选项卡中把“最近文档管理列出文件”前面的勾取消或将后面的数字选为0.
- FileChannel类的理解和使用
FileChannel类的理解和使用(java.nio.channels.FileChannel) 知识点: 1.FileChannel类及方法理解:2.普通输入输出流复制文件:3.FileChann ...
- IDEA快捷键整理(最详细的)
IDEA快捷键 Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Shift+Click,可以关闭 ...
- sql逻辑查询 理论知识
参考并转载http://www.cnblogs.com/bhtfg538/archive/2008/11/25/1341016.html First: (8) SELECT (9) DISTINCT ...
- shell脚本路径写法的注意点
1.在脚本中先cd到指定路径,再操作文件 2.如果不满足第一条,文件请写绝对路径 要不有可能会出现自己手动执行脚本没有问题,但是加入crontab却发现执行失败的情况. --------------- ...
- ubuntu14.04 64位 安装搜狗输入法
deb格式的搜狗输入法,搜狗拼音官网可以下载到 http://pinyin.sogou.com/linux/?r=pinyin (64位) 2.使用deb安装工具gdebi,这个工具能解决所有依赖问题 ...
- Java设计模式(2)单态模式(Singleton模式)
定义:Singleton模式主要作用是保证在Java应用程序中,一个类Class只有一个实例存在. 在很多操作中,比如建立目录 数据库连接都需要这样的单线程操作. 还有,singleton能够被状态化 ...