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

generatorConfig.xml and jdbc.properties都要放在resource根目录下

具体generatorConfig.xml内容如下:

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <!DOCTYPE generatorConfiguration
  3.  
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4.  
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5.  
    <generatorConfiguration>
  6.  
    <properties resource="jdbc.properties"></properties>
  7.  
    <classPathEntry location="${dbconfig.sqlServer.driverLocation}" />
  8.  
     
  9.  
    <context targetRuntime="MyBatis3">
  10.  
     
  11.  
    <!--<commentGenerator>
  12.  
    <!– 去除自动生成的注释 –>
  13.  
    <property name="suppressAllComments" value="true" />
  14.  
    </commentGenerator>-->
  15.  
    <!-- 是否生成注释 去除自动生成的注释-->
  16.  
    <commentGenerator>
  17.  
    <property name="suppressDate" value="true"/>
  18.  
     
  19.  
    <property name="suppressAllComments" value="true"/>
  20.  
    </commentGenerator>
  21.  
    <!-- 数据库连接配置 -->
  22.  
    <jdbcConnection driverClass="${dbconfig.sqlServer.driverClasss}"
  23.  
    connectionURL="${dbconfig.sqlServer.ssmDemo.read.jdbcUrl}"
  24.  
    userId="${dbconfig.sqlServer.username}"
  25.  
    password="${dbconfig.sqlServer.password}" />
  26.  
     
  27.  
    <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
  28.  
    <javaTypeResolver>
  29.  
    <property name="forceBigDecimals" value="false"/>
  30.  
    </javaTypeResolver>
  31.  
     
  32.  
    <!--配置生成的实体包
  33.  
    targetPackage:生成的实体包位置,默认存放在src目录下
  34.  
    targetProject:目标工程名
  35.  
    -->
  36.  
    <javaModelGenerator targetPackage="com.pojo"
  37.  
    targetProject="src/main/java" />
  38.  
     
  39.  
    <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
  40.  
    <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources" />
  41.  
    <!--生成Dao类存放位置-->
  42.  
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.dao" targetProject="src/main/java">
  43.  
    <property name="enableSubPackages" value="true"/>
  44.  
    </javaClientGenerator>
  45.  
    <!--生成对应表及类名-->
  46.  
    <!-- 配置表
  47.  
    schema:不用填写
  48.  
    tableName: 表名
  49.  
    enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
  50.  
    去除自动生成的例子
  51.  
    -->
  52.  
    <table schema="" tableName="UzaiSupplierStore" domainObjectName="UzaiSupplierStore" enableCountByExample="false" enableSelectByExample="false"
  53.  
    enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
  54.  
    </table>
  55.  
    <table schema="" tableName="UzaiCountry" enableCountByExample="false" enableSelectByExample="false"
  56.  
    enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
  57.  
    </table>
  58.  
     
  59.  
    </context>
  60.  
    </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的更多相关文章

  1. SpringBoot 添加mybatis generator 自动生成代码插件

    自动生成数据层代码,提高开发效率 1.pom添加插件,并指定配置文件路径 <!-- mybatis generator 自动生成代码插件 --> <plugin> <gr ...

  2. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  3. IDEA Maven Mybatis generator 自动生成代码

    IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...

  4. IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)

    IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...

  5. 使用Mybatis Generator自动生成代码

    MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码.它将内省数据库 ...

  6. IDEA使用mybatis generator自动生成代码

    主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...

  7. MyBatis Generator自动生成的配置及使用

    注意:文件名不能有中文字符,不然不能自动生成 找到MyBatis Generator.rar\MyBatis Generator\eclipse里的features和plugins文件,把这两个文件复 ...

  8. 在IDEA中使用MyBatis Generator自动生成代码

    转载自 https://blog.csdn.net/hua_faded/article/details/78900780 一.配置Maven pom.xml 文件 在pom.xml增加以下插件:   ...

  9. Mybatis generator 自动生成代码(2)

    最近准备开始做一个项目,需要开始手动创建sql,于是将Mybatis generator 工具功能强化了下. 首先,这里引入到版本一点的包 <dependency> <groupId ...

随机推荐

  1. oracle本月、上月、去年

    select trunc(sysdate, 'month') 本月第一天,        trunc(last_day(sysdate)) 本月最后一天,        trunc(add_month ...

  2. SQL复制表操作

    select * into tb1 from tb2 insert into tb1 (fld1, fld2)  select fld1, 0 from tb2 where fld0='x' 以上两句 ...

  3. Java并发编程:Lock和Synchronized <转>

    在上一篇文章中我们讲到了如何使用关键字synchronized来实现同步访问.本文我们继续来探讨这个问题,从Java 5之后,在java.util.concurrent.locks包下提供了另外一种方 ...

  4. Redis初步认识

    官网:redis.io Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的 ...

  5. [转]C# RichTextBox不用滚动条

    转自:http://blog.csdn.net/happy09li/article/details/7444912 第一种思路: richTextBox1.ScrollBars = RichTextB ...

  6. android开发(39) 使用android系统的账户中心管理账

    在android的系统设置页,有个“账户”分组,里面有很多的账户,很多app都使用了这个账户系统,比如“谷歌”,“淘宝”,“微信”,“华为”等.这些都是大公司呢,有没有可能我们也使用这个,让我们的软件 ...

  7. minerd

    云服务器 ECS Linux 异常进程 minerd 导致系统 CPU 跑满 问题现象 云服务器 ECS Linux 服务器 CPU 跑满,或者使用服务器越来越慢. 问题原因 使用 top 命令看到有 ...

  8. click只能点击一次

    <select id="s_province" name="s_province" class="s_province">< ...

  9. 数据框排序 data.frame order

    # sorting examples using the mtcars datasetattach(mtcars) # sort by mpgnewdata <- mtcars[order(mp ...

  10. Qt安装过程中: configure 时发生的经典出错信息之”Basic XLib functionality test failed!”(Z..z..) 之 MySQL support cannot be enabled due to functionality test!

    整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the include and li ...